Codejie's C++ Space

Using C++

轮子:CmdChannel的CCLibrary.h/c


    CCLibrary.h是提供给应用include的文件,与CCLbrary.c一起提供必要的宏供应用调用。

#ifndef __CC_LIBRARY__
#define __CC_LIBRARY__


#if defined(__WITH_CC__)

#include 
"CCDataType.h"

extern int cc_TelnetServer_Create();
extern int cc_InitData(const char* prompt, const char* ip, unsigned short port, int max);
extern int cc_Run();
extern int cc_IsRun();
extern int cc_RegCmd(const char* cmd, const char* help, const _cc_cmdcallback callback);
extern void cc_Destroy();
extern int cc_CmdOutput(struct _cc_telnet_clientdata* client, const char* fmt, );

#define CC_CREATE(prompt, ip, port, max) \
    
{ \
        cc_InitData(prompt, ip, port, max); \
        cc_Run(); \
    }


#define CC_DESTROY() \
    
{\
        cc_Destroy(); \
    }


#define CC_ISRUN() cc_IsRun()

#define CC_REGCMD(cmd, help, callback) cc_RegCmd(cmd, help, callback)

#define CC_CMD_OUTPUT cc_CmdOutput

#else

#define CC_CREATE(prompt, ip, port, max) {}
#define CC_DESTROY() {}
#define CC_ISRUN() 0
#define CC_REGCMD(cmd, help, callback) {}
#define CC_CMD_OUTPUT(client, fmt, ) {}

#endif


#endif


#include <memory.h>
#include 
<string.h>


#include 
"CCDataType.h"
#include 
"CCCmd.h"
#include 
"CCLibrary.h"


/* -------------------------------- */
struct _cc_data cc_Global;

DWORD WINAPI cc_TelnetCreate(LPVOID param)
{
    
return cc_TelnetServer_Create();
}


/* Export method */

int cc_InitData(const char* prompt, const char* ip, unsigned short port, int max)
{
    memset(
&cc_Global, 0sizeof(cc_Global));

    strncpy(cc_Global.telnet.prompt, prompt, 
sizeof(cc_Global.telnet.prompt));
    strncpy(cc_Global.telnet.ip, ip, 
sizeof(cc_Global.telnet.ip));
    cc_Global.telnet.port 
= port;
    cc_Global.telnet.max 
= max;

    cc_Global.telnet.run 
= 0;
    cc_Global.telnet.sock 
= INVALID_SOCKET;

    
return cc_RegDefaultCmds();
}


void cc_Destroy()
{
    cc_TelnetServer_Final();
}


int cc_Run()
{
    DWORD id 
= 0;
    HANDLE thread 
= CreateThread(NULL, 0, cc_TelnetCreate, NULL, 0&id);
    
if(thread == NULL)
        
return -1;
    cc_Global.telnet.run 
= 1;
    
return 0;
}


int cc_IsRun()
{
    
return cc_Global.telnet.run;
}

posted on 2009-12-16 22:53 codejie 阅读(187) 评论(0)  编辑 收藏 引用 所属分类: C++轮子精神


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


公告

Using C++

导航

统计

留言簿(73)

随笔分类(513)

积分与排名

最新评论

阅读排行榜

评论排行榜