Program Listing for File base_connector.h

Return to documentation for file (src/o3ds/base_connector.h)

#ifndef O3DS_BASE_CONNECTOR
#define O3DS_BASE_CONNECTOR

#include <string>
#include <vector>
#include <mutex>
#include "nng/nng.h"

namespace O3DS
{

    class Connector
    {
    public:
        enum eState { NOTSTARTED, STARTED, READING, STATE_ERROR, CLOSED };

        Connector();

        virtual ~Connector();

        virtual bool start(const char* url) = 0;

        virtual bool write(const char* data, size_t len) = 0;

        virtual size_t read(char* data, size_t len) = 0;

        virtual size_t read(char** data, size_t *len) = 0;

        // Return the state (eState) of the connection
        enum eState getState() { return mState; }

        // Get the last error
        const std::string& getError();

        // Set the error message
        void setError(const char* msg);


    protected:
        enum eState mState;
        std::string mError;
    };

    typedef void(*InDataFunc)(void*, void*, size_t);

    class AsyncConnector : public Connector
    {
    public:
        void setFunc(void* ctx, InDataFunc f);

        virtual void stop() = 0;
        InDataFunc mInDataFunc;
        void*      mContext;
    };
}

#endif  // O3DS_BASE_CONNECTOR