/***************************************************************************** ** XS.h v2.0.1 ** Interface declaration for CSP API ** ** Copyright (C) 2007 by Interactive Data Real-Time Services. ** ALL RIGHTS RESERVED *****************************************************************************/ #ifndef __XS__ #define __XS__ #include #include "TStatus.h" /***************************************************************************** ** Forward Declarations *****************************************************************************/ #ifdef _WIN32 #ifdef XS_WIN_EXPORTS #define XSCLIENT_API __declspec(dllexport) #else #define XSCLIENT_API __declspec(dllimport) #endif typedef __int64 int64_t; #define DefaultPath ".\\" #else #define XSCLIENT_API #include // for int64_t #define DefaultPath "./" #endif namespace XS { class Connection; class Msg; class Field; class Token; } /***************************************************************************** ** Class Declarations *****************************************************************************/ namespace XS { class XSCLIENT_API Connection { public: static Connection* alloc(); virtual ~Connection(); // open and close a connection // CSP IP address and port (e.g. "10.10.10.1:7022"), CSP login and password TStatus open(const char *addr, const char *user, const char *password); // Parser multicast group name (e.g. "224.2.2.1:20001") TStatus openMulticast(const char *mcastGroup); TStatus close(); // const state checking bool isOpen() const; // expose socket fd for external select() int getFD() const; TStatus send(Msg *msg); // send a message via connection; blocking TStatus receive(Msg *msg); // get the next message from connection; blocking TStatus receiveNow(Msg *msg); // get the next message from connection; nonblocking // dictionary interface Token* getTokenById(int ctfId); Token* getTokenByName(const char *name); // serialize message into \0-terminated, human-readable CTF payload // no binary CTF header/terminator TStatus deserializeMsg(Msg *msg, const char *src); TStatus serializeMsg(Msg *msg, char *dest, int len); private: // prevent from invoking unsupported methods Connection(); Connection(const Connection&); Connection& operator=(const Connection&); }; //------------------------------------------------------------------------------ class XSCLIENT_API Msg { public: static Msg* alloc(); virtual ~Msg(); const Field* addFieldInt(const Token *tok, int64_t value); const Field* addFieldDouble(const Token *tok, double value); // string buffers are copied into memory allocated within the message // where len is supplied, the first len bytes of buf may not have '\0' or other invalid CTF payload chars // where len is not supplied, buf bytes until the terminating '\0' may not have invalid CTF payload chars const Field* addFieldString(const Token *tok, const char* buf, int len); const Field* addFieldString(const Token *tok, const char* buf); const Field* findByTok(const Token *tok) const; // returns the 1st match const Field* findByPos(int position) const; // position=0 - the first field void erase(); int size() const; // returns the number of fields void print() const; // pretty-print to stdout; conn->serializeMsg() prints to string private: // prevent from invoking unsupported methods Msg(); Msg(const Msg &); Msg& operator=(const Msg &); }; //------------------------------------------------------------------------------ class XSCLIENT_API Token { public: enum TOK_TYPE { TOK_INT, TOK_DOUBLE, TOK_STRING }; int getCtfId() const; const char *getInternalCtfName() const; // returns internal '\0'-terminated string TOK_TYPE getType() const; private: // prevent from invoking unsupported methods Token(); virtual ~Token(); Token(const Token&); Token& operator=(const Token&); friend class Msg; }; //------------------------------------------------------------------------------ class XSCLIENT_API Field { public: int getString(char* buf, int len) const; // strings are copied out, up to len-1 bytes; '\0' terminator always added int getStringLen() const; // length does not include the '\0' terminator const char* getInternalString() const; // pointer to internal string, not '\0' terminated; // the internal memory is valid until the next API call int64_t getInt() const; double getDouble() const; const Token* getToken() const; private: // prevent from invoking unsupported methods Field(); virtual ~Field(); Field(const Field & ref); Field& operator=(const Field&); friend class Msg; }; /***************************************************************************** ** Global functions *****************************************************************************/ // initialize the XS API extern XSCLIENT_API TStatus initialize(const char *programName, const char * workingDir=DefaultPath); // call when finished using the API extern XSCLIENT_API TStatus api_finalize(); // return C string associated with TStatus extern XSCLIENT_API const char* explainStatus(TStatus); // return C string associated with an enumeration extern XSCLIENT_API const char* explainEnumeration(int whichEnum, int enumValue); // set how long con->open() shall block on socket connect() extern XSCLIENT_API void setTimeOut(int milliseconds); /***************************************************************************** ** Global constants *****************************************************************************/ const int TIME_ENUM_SRC_ID = 922; } // end namespace XS #endif // __XS__