91 lines
2.3 KiB
C++
91 lines
2.3 KiB
C++
#ifndef CDUTILS_CORE_H
|
|
#define CDUTILS_CORE_H
|
|
|
|
#include "cdutils_types.h"
|
|
#include "cdutils_protocol.h"
|
|
#include "piconnection.h"
|
|
#include "pidatatransfer.h"
|
|
|
|
|
|
namespace CDUtils {
|
|
|
|
class CDCore;
|
|
|
|
|
|
class __Core_Initializer__ {
|
|
public:
|
|
__Core_Initializer__();
|
|
~__Core_Initializer__();
|
|
static int count_;
|
|
static CDCore * __instance__;
|
|
};
|
|
|
|
|
|
class CDCore: public PIObject
|
|
{
|
|
PIOBJECT(CDUtils::CDCore)
|
|
friend class __Core_Initializer__;
|
|
friend class CDSection;
|
|
friend class Interface;
|
|
public:
|
|
static CDCore * instance();
|
|
|
|
EVENT(K_Sended)
|
|
EVENT(K_SendFail)
|
|
EVENT(K_Received)
|
|
EVENT(K_ReceiveFail)
|
|
EVENT(K_ChangedGlobal)
|
|
EVENT_HANDLER(void, K_Send);
|
|
EVENT_HANDLER(void, K_Request);
|
|
EVENT_HANDLER2(void, K_DirectChange, PIDeque<int>, path, PIString, value);
|
|
|
|
void cd_write (CDSection * cd, PIIODevice * d);
|
|
void cd_read (CDSection * cd, PIIODevice * d);
|
|
void cd_parse (CDSection * cd, PIIODevice * d);
|
|
void cd_update (CDSection * cd, PIIODevice * d, UpdateModeFlags mode);
|
|
void cd_calculate(CDSection * cd);
|
|
void cd_send (CDSection * cd, CDPacketType pt, bool direct = false);
|
|
void initApp();
|
|
void initPult();
|
|
void init(const PIString & configuration);
|
|
void startPing();
|
|
bool inProgress() {return sendt.isRunning();}
|
|
|
|
CDSection & k() {return k_;}
|
|
CDSection * root(CDType::cdT cdt);
|
|
PIString typeLetter(CDType::cdT cdt);
|
|
|
|
static PIString pultConfig() {return PIString(pult_config);}
|
|
static PIString appConfig() {return PIString(app_config);}
|
|
|
|
private:
|
|
CDCore();
|
|
~CDCore();
|
|
EVENT_HANDLER2(void, dataReceived, const PIString &, from, const PIByteArray &, data);
|
|
EVENT_HANDLER1(void, dtSendRequest, PIByteArray &, data);
|
|
EVENT_HANDLER1(void, dtReceiveFinished, bool, ok);
|
|
EVENT_HANDLER(void, sendThread);
|
|
EVENT_HANDLER(void, xTimerTick);
|
|
void initRoot(CDSection * r);
|
|
PIByteArray makeHeader(CDPacketType type, int session_id = 0) const;
|
|
void sendDirect(PIByteArray & ba);
|
|
void sendThreaded(PIByteArray & ba);
|
|
void procReceivedPacket(PIByteArray & ba);
|
|
|
|
static const char app_config[], pult_config[];
|
|
PIConnection connection;
|
|
PIDataTransfer datatr;
|
|
PIByteArray send_data;
|
|
PIThread sendt;
|
|
PITimer x_timer;
|
|
CDSection k_, x_, c_;
|
|
|
|
};
|
|
|
|
|
|
static __Core_Initializer__ __Core_initializer__;
|
|
|
|
}
|
|
|
|
#endif // CDUTILS_CORE_H
|