// Copyright (c) 2014, IOnU Security, Inc. // Copyright (c) 2016, Sequence Logic, Inc. All rights reserved. #ifndef PEER_OBSERVER #define PEER_OBSERVER #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 namespace sequencelogic { /** * Used to notify a client on specific actions being taken, message processed, etc., during * a sync and message dispatch call. */ class SL_CPPCORE_EXPORT PeerObserver { public: static const char ACTION_DOWNLOAD_FILE[]; static const char ACTION_UPLOAD_FILE[]; static const char ACTION_METADATA[]; static const char ACTION_DELETE_FILE[]; // Error codes... enum ERROR_CODES { ERR_DUPLICATE_DEVICE = 100, ERR_NO_NETWORK_SVC = 101, ERR_DROPPED_MSG = 102 }; PeerObserver() {} virtual ~PeerObserver() {} ////// Observer must cough up a directory for storing limited unencrypted work data virtual std::string getWorkingDirectory() = 0; ////// SyncAndMessageDispatch / PubSub initiated /** * Invoked when a new message was received. */ virtual void onSubscribedMessageReceived(const std::string &msg) = 0; /** * Invoked by PeerOutboundThread when a reply message was sent. * Typically observer has little work to perform, other than perhaps doing some UX status updating. * @param msg */ virtual void onResponseSent(const std::string &msg) = 0; /** * Called when message is disposed. * @param fm */ virtual void onMessageDisposed(const std::string &msg) = 0; /** * Incoming subscribed messages that require manual user reply/action will fire this method from the peer * system after the message is persisted. * @param msg */ virtual void onMessagePersisted(const std::string &msg) = 0; /** * Called when a message is removed. * @param msg */ virtual void onMessageRemoved(const std::string &msg) = 0; /** * Normally PubSubMessages that return true when isManualUserReplyRequired is invoked * require manual user intervention. This observer method allows an automatic "bot" reply * to those normally manual reply messages. * @param msg An isManualUserReplyRequired message * @param reply A reply message to msg; the responseData will need to be indicated by observer * @return null if normal message persistence is required; non-null reply object if a "bot" reply * is desired * * @return A JSON string to reply to the message with. We will take ownership of the memory. */ virtual std::string automaticReplyToManualMessage(const std::string &msg, const std::string &reply) = 0; //////// SAMD internal virtual void onInactivityTimeReached() = 0; //////// Various places initiate //////// StorageGuardService initiated virtual void onSyncStart(const std::string &node) = 0; virtual void onSyncComplete(const std::string &node) = 0; virtual void onSyncError(const std::string &node, const std::string &ex) = 0; virtual void onSyncUploaded(const std::string &eye) = 0; virtual void onSyncDownload(const std::string &eye) = 0; virtual void onSyncDelete(const std::string &path) = 0; //////// SAMD messages... /** * Notify the client that sync and message dispatch is starting. * * @param pUrn The device URN that is being sync'd */ virtual void onSyncAndDispatchStart(const std::string &urn) = 0; /** * Notify the client that sync and message dispatch has ended. * * @param pUrn The device URN that is being sync'd */ virtual void onSyncAndDispatchStop(const std::string &urn) = 0; //////// State and Errors /** * Was in an error (disconnected) state and now connected again. * @return false to skip internal sync logic; true to internally invoke subscribe */ virtual bool onConnectionRestored() = 0; virtual void onFatalError(int code, const std::string &msg) = 0; virtual void onServiceException(const std::string &urlOrIdentifier, const std::string &ex) = 0; }; } #endif