169 lines
7.3 KiB
C++
169 lines
7.3 KiB
C++
#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 <functional>
|
|
#include <memory>
|
|
#include <vector>
|
|
|
|
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.<br>Either no connect tried or disconnected
|
|
NoneServer = 1, // Server has disconnected
|
|
Lost = 2, // The connection is lost<br>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<void(ServerEvent event, const SadDetectedServer &detectedServer)> onServerEvent;
|
|
function<void(string serverID, string serverComputerName, string serverName, int serverStepTime, Connection connectionStatus, Connection oldConnectionStatus)> onConnectionStatus;
|
|
function<void(ProjUpdate state, string projectId)> onProjectUpdate;
|
|
function<void(ObjectEvent event, bool isRemote, const SType &sType)> onSpitType;
|
|
function<void(ObjectEvent event, bool isRemote, const SType &sType, const SObject &sObject)> onSpitObject;
|
|
function<void(string playerID, string playerName, char playerType, bool playerIsRunning, uint64_t timeFrames)> onPlay;
|
|
function<void(string playerID, string spitTypeID, bool playerIsRunning, bool started, bool ended, double value)> onPlaySpitType;
|
|
function<void(const SType &sType, const SObject &sObject, uint64_t p_FrameInsideObject, int value)> onPlayRemoteObjectStatus;
|
|
function<bool(bool knownType, bool createdByClient)> onCheckSpitTypeVeto;
|
|
function<bool(bool knownType)> onCheckSpitObjectVeto;
|
|
};
|
|
|
|
struct InternalCallbacks {
|
|
function<void(int ms)> delay;
|
|
function<int(Message::OPPart &msg)> sendMessage;
|
|
function<void(Message &msg)> 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<unique_ptr<Message>> 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<char> data);
|
|
|
|
unique_ptr<Message::Connect> createConnectMessage(string serverIP, string serverPort, string loginName, string loginPassword);
|
|
|
|
std::vector<char> createMessage(Message::OPPart &spitMessageOPPart);
|
|
void parseMessage(Message &message);
|
|
void addOvertakingMessage(unique_ptr<Message> 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.<br>
|
|
// * 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.<br>
|
|
* 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.<br>
|
|
* @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.<br>
|
|
* 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.<br>
|
|
* @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<SObject> mSpitObjects;
|
|
SpitRepo<SType> mSpitTypes;
|
|
SpitRepo<SObject> mRemoteSpitObjects;
|
|
SpitRepo<SType> mRemoteSpitTypes;
|
|
};
|
|
|
|
} // namespace spit
|