You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

137 lines
3.6 KiB

#ifndef __MOJO_REMOTE_CLIENT_HEADER__
#define __MOJO_REMOTE_CLIENT_HEADER__
#include "../../components/base/basicLogCollection.h"
#include "../../components/base/basicThread.h"
#include "../../data/net/clientPort.h"
#include "../../data/protocol/protocol.h"
#include "../../data/protocol/protocolARGUS_DATA.h"
#include "../common/dataBinder.h"
class mojoKernel;
typedef struct S_RPC_CMD_RECORD
{
uint8_t CMD;
size_t DATA_SIZE;
void * DATA;
} RPC_CMD_RECORD;
typedef basicRing<RPC_CMD_RECORD> RPC_CMD_QUEUE;
class mojoVideoTransferHelper
{
private:
basicLogCollection * m_pLog;
char m_cCurrentFile[MAX_PATH];
bool m_bVideoExists;
bool m_bVideoOpened;
uint64_t m_nRemoteRefID;
FILE * m_pFD;
ARGUS_DATA_VIDEO_INFO m_sIn;
uint32_t m_nBufferSize;
uint8_t * m_pBuffer;
uint64_t m_nCTSMS; // future use for Target Binding ( history filtering )
public:
explicit mojoVideoTransferHelper(uint32_t buffer_size = ARGUS_RPC_DEFAULT_MEDIA_CHUNK);
~mojoVideoTransferHelper();
bool init(VIDEO_SEGMENT_INFO * ptr);
uint8_t * getNextChunk(uint32_t req_chunk_size, uint32_t * ack_size);
ARGUS_DATA_VIDEO_INFO * getVideoInfo();
void clear();
void abort();
void registerEventID(uint32_t local, uint64_t remote);
void setRemoteReferenceID(uint64_t rid)
{
m_nRemoteRefID = rid;
}
uint64_t getRemoteReferenceID()
{
return m_nRemoteRefID;
}
};
typedef struct S_VTR_HELPER
{
mojoVideoTransferHelper * ptr;
uint8_t state;
uint32_t ts;
} VTR_HELPER;
typedef std::vector<VTR_HELPER *> V_VIDEO_TRANSFER_HELPERS;
typedef std::queue<mojoVideoTransferHelper *> Q_VIDEO_TRANSFER_HELPERS;
class mojoRemoteClient : public basicThread, public protocolParser
{
private:
basicLogCollection * m_pLog;
mojoKernel * m_pMaster;
ARGUS_DATA_MOJO_INFO m_sINFO;
bool m_bUseBackupServer;
uint8_t m_bActiveServer;
uint8_t m_bCloseCommunicationReason;
clientPort * m_pPort;
basicMutex m_mQueryProtector;
basicMutex m_mAutomationStageProtector;
basicMutex m_mAutomationFreezer;
RPC_CMD_QUEUE * m_qCMD;
basicMutex m_mCurrentCMDProtector;
RPC_CMD_RECORD * m_pCurrentCMD;
basicMutex m_mCurrentVTRProtector;
V_VIDEO_TRANSFER_HELPERS m_vVTRHelpers;
// mojoVideoTransferHelper * m_pVideoHelper;
uint32_t m_nQueryMessage;
uint32_t m_nInbondSerial;
uint32_t m_nOutbondSerial;
uint8_t m_bAutomationStage;
uint8_t m_bTOCounter;
bool m_bShutdownCommunication;
bool m_bCommunicationEstablished;
bool m_bRegisteredWithRemotePeer;
bool peer_send_rpc_pack(RPC_CMD_RECORD * ptr);
void enqueueInfoMsg();
void enqueueStatMsg();
void enqueueTimeReq();
void enqueueDisconnect(uint8_t reason = 0);
uint8_t getAutomationStage();
void setAutomationStage(uint8_t stg);
bool validateTransaction();
bool pushNewTransaction(RPC_CMD_RECORD * ptr);
bool fetchNewTransaction();
void finishTransaction();
void flushTransactions();
basicMutex m_mTOProtoctor;
void setTO(uint8_t seconds);
bool decTO();
VTR_HELPER * getHelperByDBID(uint64_t dbid);
protected:
virtual int packetChecker(U8 * Buffer, size_t BufferSize);
virtual protocolPackage * packetExtractor(U8 * Buffer, size_t BufferSize);
virtual bool packetHandler(protocolPackage * Package);
virtual void m_fThreadProc(void);
public:
explicit mojoRemoteClient(mojoKernel * ptr);
~mojoRemoteClient();
virtual bool create();
// bool createVideoTransferTask( ARGUS_DATA_VIDEO_SEGMENT *ptr );
bool validate();
bool addEvent(EVENT_CONTAINER * ptr);
bool addVideo(VIDEO_SEGMENT_INFO * ptr);
};
#endif