📄 ctpmanager.h
字号:
/*
* Copyright (C) 2003-2007 Funambol, Inc
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY, TITLE, NONINFRINGEMENT or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA
*/
#ifndef INCL_CTP_MANAGER
#define INCL_CTP_MANAGER
/** @cond DEV */
#include <stdio.h>
#include <windows.h>
#include "CTPMessage.h"
#include "CTPConfig.h"
#include "worker.h"
#define CTP_PROTOCOL_VERSION 0x10 /**< CTP Protocol version = 1.0 */
#define CTP_RETRY_INCREASE_FACTOR 2 /**< Each time the CTP connection is broken, we double the ctpRetry time */
#define LEAVING_STATE_TIMEOUT 20 /**< Timeout to receive the last OK message before leaving, in seconds */
/**
* The class to manage the CTP connection, singleton.
*/
class CTPManager {
private:
/// Pointer to CTPManager instance
static CTPManager* pinstance;
/// The configuration of CTP
CTPConfig config;
/// The socket used
SOCKET ctpSocket;
/// Handle of main CTP thread, which implements the CTP process
HANDLE ctpThread;
/// Handle of thread used to receive msg from Server
HANDLE receiveThread;
/// Handle of thread used to send ready msg to Server
HANDLE heartbeatThread;
/// Store the received message from Server
CTPMessage* receivedMsg;
string createMD5Credentials();
/**
* Sends a generic CTPMessage through the socket 'ctpSocket'.
* The socket must be already opened calling 'startConnection()'.
* @return the number of bytes sent (SOCKET_ERROR = -1 in case of error)
*/
int sendMsg(CTPMessage* message);
protected:
// Constructor
CTPManager();
public:
// Method to get the sole instance of CTPManager
static CTPManager* getInstance();
~CTPManager();
HANDLE startCTP(HANDLE stpThread);
int stopCTP();
int openConnection();
int closeConnection();
int receive();
bool stopThread(HANDLE thread, DWORD exitcode = 0);
// Create and send messages through the socket.
int sendReadyMsg();
int sendAuthMsg();
int sendByeMsg();
CTPMessage* receiveStatusMsg();
/**
* Returns pointer to (internally owned) CTPConfig
*/
CTPConfig* getConfig() { return &config; }
};
/** @endcond */
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -