// Copyright (c) 2014, IOnU Security, Inc. // Copyright (c) 2016, Sequence Logic, Inc. All rights reserved. #ifndef SYNC_AND_MESSAGE_DISPATCH #define SYNC_AND_MESSAGE_DISPATCH #ifdef WIN32 #ifdef SL_CPPCORE_DLLEXPORT #define SL_CPPCORE_EXPORT __declspec(dllexport) #else #define SL_CPPCORE_EXPORT __declspec(dllimport) #endif #else #define SL_CPPCORE_EXPORT #endif #include #include #include #include "websvcs.h" namespace sequencelogic { class PubSubMessage; class NotifyClient; class JSONObject; class WebSvcs; class OfficeSvcs; class PeerObserver; class File; class SL_CPPCORE_EXPORT SyncAndMessageDispatch { public: /** * SAMD constructor. The client must provide, at a minimum, an observer, a chat service instance, * a web server instance, and an office service instance. SAMD does NOT take ownership of these objects. */ SyncAndMessageDispatch(const std::string &K2Host, const std::string &devUrn, PeerObserver *pObserver, WebSvcs *pWebSvc); ~SyncAndMessageDispatch(); /** * Set the K2 host, and the dev URN. */ void setK2HostAndUrn(const std::string &k2Host, const std::string &devUrn) { _k2Host = k2Host; _devURN = devUrn; } /** * Get the observer instance. */ PeerObserver *getInstanceObserver(); /** * Terminate K2 client. */ void terminate(); /** * Log into the K2 server. */ bool k2Login(); /** * Get K2 stats. */ std::string k2Statistics(); /** * Log out of the K2 server. */ void k2Logout(); /** * Tell K2 what offices to notify us for. */ void k2StatusSelect(const std::string &offices); /** * Get K2 status. */ std::string getK2Status(); /** * Is K2 connected, and working? */ bool isGoodK2Status(); /** * Callback for K2, called when we get a K2 message. */ static void k2DataReceived(const char *pK2Info); /** * Convience functions for storing inactivity time. */ void setInactivityLogoutTime(long nInactiveTime); long getInactivityLogoutTime(); /** * The workhorse of this class. Get and process all pubsub messages. */ void subscribeAndDispatch(); protected: private: #if defined(WIN32) || defined(_WIN32) #pragma warning(push) #pragma warning(disable:4251 4275) // Disable the dumbass XXXX needs to have dll-interface. #endif void disposeOf(const PubSubMessage &msg); void doReply(const PubSubMessage &msg); void doRequest(const PubSubMessage &msg); PeerObserver *_pPeerObserver; WebSvcs *_pWebSvc; std::string _k2Host; std::string _devURN; std::string _k2Status; bool _k2Good; bool _k2Error; long _inactivityLogoutTime; typedef std::map UrnToDispMap; typedef UrnToDispMap::iterator UrnToDispMapIter; static UrnToDispMap _k2ClientMap; // Get the mount type from message data... WebSvcs::MOUNT_TYPE getMountType (const std::string &mount); #if defined(WIN32) || defined(_WIN32) #pragma warning(pop) #endif }; }; #endif