I have a bit of a quandary I was hoping for some expert guidance on. Keep in mind I am not a C++ developer, but I have worked with the language a bit.
I have a native C++ API which I am currently wrapping in managed C++ in order to expose the API to .Net clients. So far, so good, everything is working out just fine. However, I have ventured into the callback portion of the API and I am stumped.
In the native API, the callback functionality is abstract. It is left to the consumer to create their class, inheriting from the abstract and coding the actual implementation of the method. Here is the callback.h file from the native API:
Expand|Select|Wrap|Line Numbers
- #ifndef Callback_h
- #define Callback_h
- namespace NMSP {
- class Conn;
- class Msg;
- /** @class Callback
- * @brief This class is the abstract base class for received message callbacks.
- * A user created class, derrived from this class, can be passed into
- * %Subscribe() and %Request() to have user code executed asynchronously
- * when a message is received.
- *
- * Example Callback class:
- * @code
- * class PublishCallback : public Callback
- * {
- * public:
- * virtual void CALL_TYPE OnMessage(Conn *conn, Msg *msg)
- * {
- * const char *tmp;
- * msg->ToXML(tmp);
- * cout << tmp << endl;
- * }
- * };
- * @endcode
- *
- * Example Callback registration:
- * @code
- * PublishCallback cb;
- * result = conn->Subscribe("NMSP.*.publish",&cb);
- * if( result.isError() )
- * // handle error
- * @endcode
- *
- * @sa Conn::Subscribe(const char *subject, Callback *cb) @n
- * Conn::Request(Msg *request, long timeout, Callback *cb)
- */
- class API Callback
- public:
- virtual void CALL_TYPE OnMessage(Conn *conn, Msg *msg) = 0;
- };
- } //namespace NMSP {
- #endif // Callback_h
1. just create a class in managed c++ inheriting from callback? e.g. class ManagedCallback : public Callback? Or,
2. do I create an unmanaged implementation, then create a managed C++ wrapper class for the implementation?
I have been struggling with this for awhile, so any help is greatly appreciated.
Thom