#pragma once #include "sad_DetectedServer.hpp" #include "spit_message.hpp" #include "spit_object.hpp" #include "spit_player.hpp" #include "spit_repo.hpp" #include "spit_type.hpp" #include #include #include using namespace std; namespace spit { class SProcessor { public: enum class ProjUpdate { ServerLoaded, StartTransfer, EndTransfer, ServerClosed, }; enum class ServerEvent { Detect, Lost, Changed, }; enum class ObjectEvent { Created, Changed, Deleted }; enum class Connection { None = 0, // No Connection established.
Either no connect tried or disconnected NoneServer = 1, // Server has disconnected Lost = 2, // The connection is lost
Either because of a network crash or because the server no longer responds. Ok = 3, // Connection to the serv er is established. TryConnection = 4, // A connection to the server is tried. }; struct Callbacks { function onServerEvent; function onConnectionStatus; function onProjectUpdate; function onSpitType; function onSpitObject; function onPlay; function onPlaySpitType; function onPlayRemoteObjectStatus; function onCheckSpitTypeVeto; function onCheckSpitObjectVeto; }; struct InternalCallbacks { function delay; function sendMessage; function parseMessage; }; static constexpr int MAX_OVERTAKING_SPIT_MESSAGES = 10; //----- SProcessor ----- public: SProcessor(string name, string projName, string hostName, string guid, Callbacks calls, InternalCallbacks intern); virtual ~SProcessor(); private: Callbacks mCallbacks; InternalCallbacks mInternCallbacks; string mName; string mGuid; string mProjName; string mComputerName; uint8_t mMessageNumberSend{1}; int mMessageNumberReceived{-1}; // set to -1 because the first received message will set the number (1..255) vector> mOvertakingMessages; string mServerID{}; string mServerProjectID; string mServerProjectName; int mServerFramesPerSecond; public: string getID() { return mGuid; } string getName() { return mName; } string getProjName() { return mProjName; } string getComputerName() { return mComputerName; } void setActionType(string spitypeID, bool actionAssigned); void setActionObject(string objectID, bool actionAssigned); void checkParseMessageData(vector data); unique_ptr createConnectMessage(string serverIP, string serverPort, string loginName, string loginPassword); std::vector createMessage(Message::OPPart &spitMessageOPPart); void parseMessage(Message &message); void addOvertakingMessage(unique_ptr message); int sendOvertakingMessage(int msgNumRec); void resetMessageNumberReceived(); string getServerProjectID() { return mServerProjectID; } string getServerProjectName() { return mServerProjectName; } int getServerFramesPerSecond() { return mServerFramesPerSecond; } // /** // * Creates a SPITType for application actions.
// * These SPITTypes will be automatically added to the SPITType-List and sended to the server. // * @param p_ID an unique of the SPITType, these are always the same per client approach. Different client approaches should use different ids. // * @param p_GroupName a name which groups the actions/SPITTypes // * @param p_Name the name of the Action/SPITType // * @param p_DefaultDelay maybe there is an default delay until the action starts, this is only used for graphical representations, 0 is allowd // * @param p_DefaultDuration maybe the action has a default duration, this is only used for graphical representations, 0 is allowd // * @param p_Fixed true = the server is not allowed to change this SPITType, false = the server may change or delete this SPITType // * @param p_ProjectIndepended true = the SPITType belongs to a specific project, false = the SpitType always exists for every project // * @return the pointer to the new SPITType. // */ SType *createType(string iD, string groupName, string name, uint64_t defaultDelay, uint64_t defaultDuration, bool fixed, bool projectIndepended); int sendTypeInternal(SType &sType); /** * If a client wants to change a SPITType, he should send it to the server.
* If the SPITTye is a fixed one and not created by the client himself, then an eventSPITType can be sent from the server, which cancels the change.
* @param spitypeID the id of the SPITType to remove. * @return 0 = is sended, -1 = is not sended */ bool changeType(SType *spitType); /** * If a client wants to remove a SPITType, he should send it to the server.
* If the SPITTye is a fixed one and not created by the client himself, then an eventSPITType can be sent from the server, which cancels the deletion.
* @param spitypeID the id of the SPITType to remove. * @return 0 = is sended, -1 = is not sended */ int removeType(string spitypeID); int removeObject(string objectID); bool changeObject(SObject *sObject); void sendRemoteObject(string objectID, int valuePpm = 0, char valueFlag = 0x00); void resetConfirmedFlags() { SType::setConfirmedFalse(mSpitTypes); SObject::setConfirmedFalse(mSpitObjects); } private: void parseReportProject(Message::ReportProject &message); void parseCloseProject(Message::CloseProject &message); void parseRequestProjectTransfer(Message::RequestProjectTransfer &message); void parseStartProjectTransfer(Message::StartProjectTransfer &message); void parseEndProjectTransfer(Message::EndProjectTransfer &message); void parseReportType(Message::ReportType &message); void parseRemoveType(Message::RemoveType &message); void parseReportObject(Message::ReportObject &message); void parseRemoveObject(Message::RemoveObject &message); void parsePlayStart(Message::PlayStart &message); void parsePlayObject(Message::PlayObject &message); void parsePlayEnd(Message::PlayEnd &message); void parseReportPlayStatus(Message::ReportPlayStatus &message); int sendObjectInternal(SObject *sObject); SpitRepo mSpitObjects; SpitRepo mSpitTypes; SpitRepo mRemoteSpitObjects; SpitRepo mRemoteSpitTypes; }; } // namespace spit