远程调用内核接口(remote call kernel)

--------------------------------------------------------------------------------
标题: 远程调用内核接口(remote call kernel)
作者: 叶飞虎
版本: 4.0.0.0
日期: 2013.09.12
--------------------------------------------------------------------------------

1. 概述
    RCK(remote call kernel 缩写)为远程调用内核, 其通讯协议为自定义数据流协议。
RCK 负责远程调用过程中的数据组织, 并不关心实际物理通讯协议, 实则属于逻辑层通讯
协议。

    RCK 通讯槽接口(RCKSlot)负责数据接收和发送, 属于通讯的适配层, 由第三方来实现
实际的数据传输接口。

    RCK 包含 Application, Function, Connection, Command, Response 和 Fields 六
大类, 其主要功能如下:
    a. Application 类主要负责 Function 的组织和 Response 的分发执行;
    b. Function    类主要负责 Function 的定义及按各模式调用;
    c. Connection  类主要负责登录对端应用, Command 请求执行, Response 应答管理,
       以及发送和接收数据等等;
    d. Command     类主要负责函数参数传入, 以及返回值和返回字段值读取;
    e. Response    类主要负责对端指定 Function 请求的执行处理, 如参数读取、返回
       值编辑及提交;
    f. Fields      类主要负责数据库字段值及定义集的组包和拆包。

2. RCK 通讯槽接口定义
    参见 <RCKSlot.h> 文件

// =======================================
// Unit   : RCK Slot (RCK 通讯槽接口)
// Version: 4.0.0.0 (build 2013.08.17)
// Author : Kyee Ye
// Email  : kyee_ye(at)126.com
// Copyright (C) Kyee workroom
// =======================================

#ifndef _RCKSlot_H_
#define _RCKSlot_H_

namespace RCKernel
{

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/* 常量定义 */

// 返回值及错误码
enum TRCKResult
        {krSuccess         =  1,       // 成功
         krFailure         =  0,       // 失败
         krUnknown         = -1,       // 未知错误
         krNotExist        = -2,       // 不存在(如: 连接对象)
         krNotConnect      = -3,       // 连接未打开
         krNonsupport      = -4,       // 不支持
         krVersion         = -5,       // 版本不兼容
         krTimeout         = -6,       // 操作超时
         krPassword        = -7,       // 密码错误
         krIsExisted       = -8,       // 已存在
         krIsRefused       = -9,       // 被拒绝
         krIsIllegal       = -10,      // 不合法
         krIsNullName      = -11,      // 名字为空
         krAttrInvalid     = -12,      // 属性无效
         krStateInvalid    = -13,      // 状态无效
         krHandleInvalid   = -14,      // 句柄无效
         krAccessIllegal   = -15};     // 存取非法

// 通讯槽的属性项
enum TRCKSlotAttrib
        {ksaError          = 0,        // 通讯槽打开失败的错误信息
         ksaState          = 1,        // 通讯槽的状态
         ksaConnObj        = 2,        // 通讯槽的绑定连接对象
         ksaCurrAddr       = 3,        // 通讯槽的本地地址
         ksaCurrPort       = 4,        // 通讯槽的本地端口号
         ksaPeerAddr       = 5,        // 通讯槽的对端地址
         ksaPeerPort       = 6,        // 通讯槽的对端端口号
         ksaSlotMaxSize    = 7,        // 通讯槽的数据包最大长度, 默认值: 8192
         ksaOnDisconnect   = 8,        // 通讯槽的 OnDisconnect 事件, 断开通讯(TRCKSlotOnEvent)
         ksaOnRecvEvent    = 9,        // 通讯槽的 OnRecvEvent  事件, 接收事件(TRCKSlotOnEvent)
         ksaOnRecvData     = 10,       // 通讯槽的 OnRecvData   事件, 接收数据(TRCKSlotOnRecvData)
         ksaBaseExtended   = 0x10000}; // 通讯槽的扩展属性基数: 扩展属性项
                                       // (注: 扩展属性项必须小于 0x10000)

// 通讯槽的状态
enum TRCKSlotState
        {kssInactive       = 0,        // 未打开
         kssClosing        = 1,        // 正在关闭
         kssOpening        = 2,        // 正在打开
         kssOpened         = 3};       // 已经打开

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/* 通讯槽对象的函数类型定义 */

// 操作通讯槽的函数类型
typedef void  (__stdcall *TRCKSlotOp)(void* ASlotObj);

// 打开通讯槽的函数类型(返回值定义为 TRCKResult)
typedef long  (__stdcall *TRCKSlotOpen)(void* ASlotObj, long ATimeout);

// 接收数据的函数类型(返回值为接收成功的数据尺寸, 若小于 0 则为错误码)
typedef long  (__stdcall *TRCKSlotRecv)(void* ASlotObj, void* AData, long ASize);

// 发送数据的函数类型(返回值为发送成功的数据尺寸, 若小于 0 则为错误码)
typedef long  (__stdcall *TRCKSlotSend)(void* ASlotObj, const void* AData, long ASize);

// 可以发送的函数类型(返回值为可以发送的数据尺寸, 若小于 0 则为错误码)
typedef long  (__stdcall *TRCKSlotCanSend)(void* ASlotObj, long ASize);

// 取通讯槽整型属性的函数类型(返回值为属性值, ARetCode 为失败的返回码, 允许为空)
typedef long  (__stdcall *TRCKSlotGetInt)(void* ASlotObj, long Attrib, long* ARetCode);

// 取通讯槽指针属性的函数类型(返回值为属性值, ARetCode 为失败的返回码, 允许为空)
typedef void* (__stdcall *TRCKSlotGetObj)(void* ASlotObj, long Attrib, long* ARetCode);

// 取通讯槽字符串属性的函数类型(返回值为属性值, ARetCode 成功时为属性值尺寸, 否则为返回码, 允许为空)
typedef char* (__stdcall *TRCKSlotGetStr)(void* ASlotObj, long Attrib, long* ARetCode);

// 设置通讯槽整型属性的函数类型
typedef long  (__stdcall *TRCKSlotSetInt)(void* ASlotObj, long Attrib, long  AValue);

// 设置通讯槽指针属性的函数类型
typedef long  (__stdcall *TRCKSlotSetObj)(void* ASlotObj, long Attrib, void* AValue);

// 设置通讯槽字符串属性的函数类型
typedef long  (__stdcall *TRCKSlotSetStr)(void* ASlotObj, long Attrib,
                                    const char* AValue,   long ASize);

// 通讯槽对象事件的回调函数类型
typedef void  (__stdcall *TRCKSlotOnEvent)(void* ASlotObj, void* AConnObj);

// 通讯槽对象 OnRecvData 事件的回调函数类型
// 注: 若 Recv 方法为 NULL 则通过 OnRecvData 事件接收数据,
//     否则通过 OnRecvEvent  事件来调用 Recv 方法接收数据.
typedef void  (__stdcall *TRCKSlotOnRecvData)(void* ASlotObj, void* AConnObj,
                                        const void* AData,    long  ASize);

// 通讯槽对象的方法列表
#pragma pack(push, 1)
typedef struct
{
   long              Size;             // = sizeof(TRCKSlotMethods)

   TRCKSlotOpen      Open;             // 打开通讯槽
   TRCKSlotOp        Close;            // 关闭通讯槽
   TRCKSlotOp        FreeObj;          // 释放通讯槽对象

   TRCKSlotRecv      Recv;             // 接收数据
   TRCKSlotSend      Send;             // 发送数据
   TRCKSlotCanSend   CanSend;          // 可以发送的数据尺寸

   TRCKSlotGetInt    GetInt;           // 取通讯槽整型属性
   TRCKSlotGetObj    GetObj;           // 取通讯槽指针属性
   TRCKSlotGetStr    GetStr;           // 取通讯槽字符串属性

   TRCKSlotSetInt    SetInt;           // 设置通讯槽整型属性
   TRCKSlotSetObj    SetObj;           // 设置通讯槽指针属性
   TRCKSlotSetStr    SetStr;           // 设置通讯槽字符串属性
} TRCKSlotMethods, *PRCKSlotMethods;
#pragma pack(pop)

}

#endif


 

3. RCK 接口定义
    参见 <RCKernel.h> 文件

// =======================================
// Unit   : RC Kernel
// Version: 4.0.0.0 (build 2013.09.02)
// Author : Kyee Ye
// Email  : kyee_ye(at)126.com
// Copyright (C) Kyee workroom
// =======================================

#ifndef _RCKernel_H_
#define _RCKernel_H_

#include "RCKSlot.h"

#pragma comment(lib, "RCKernel.lib")

namespace RCKernel
{

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/* 常量定义 */

// 数据类型
enum TRCKDataType
        {kdtNone           = 0,        // 无类型
         kdtString         = 1,        // 字符串类型  (自定义尺寸)
         kdtInteger        = 2,        // 整型类型    (4 Bytes)
         kdtBoolean        = 3,        // 布尔类型    (1 Bytes)
         kdtDouble         = 4,        // 浮点类型    (8 Bytes)
         kdtStruct         = 5,        // 结构类型    (自定义尺寸)
         kdtByte           = 6,        // 字节        (1 Bytes)
         kdtWord           = 7,        // 双字节      (2 Bytes)
         kdtSmallint       = 8,        // 16位整型    (2 Bytes)
         kdtInt64          = 9,        // 64位整型    (8 Bytes)
         kdtDateTime       = 10,       // 日期时间类型(8 Bytes)
         kdtCurrency       = 11};      // 货币类型    (8 Bytes)

// 接口的属性项
enum TRCKAttrib
        {kaVersion         = 0,        // 接口版本信息, 格式: "x.x.x.x (build yyyy.mm.dd)"
         kaAppCount        = 1,        // 应用个数
         kaCmdCount        = 2,        // 命令个数
         kaConnCount       = 3,        // 连接个数
         kaDealThreads     = 4,        // 处理线程最大个数, 默认值: 16
         kaDealCacheSize   = 5,        // 处理线程缓冲池尺寸, 默认值: 16
         kaSendThreads     = 6,        // 发送线程最大个数, 默认值: 8
         kaSendCacheSize   = 7,        // 发送线程缓冲池尺寸, 默认值: 8
         kaBaseAppObj      = 0x10000,  // 应用索引基数: 应用对象
         kaBaseAppName     = 0x20000,  // 应用索引基数: 应用名
         kaBaseConnObj     = 0x40000}; // 连接索引基数: 连接对象

// 应用的属性项
enum TRCKAppAttrib
        {kaaData           = 0,        // 自定义数据
         kaaName           = 1,        // 应用名
         kaaState          = 2,        // 应用的状态
         kaaPassword       = 3,        // 应用的密码
         kaaFuncCount      = 4,        // 应用的函数个数
         kaaConnCount      = 5,        // 应用的已连接数
         kaaMaxThreads     = 6,        // 应用的回调函数处理线程最大个数, 默认值: 8
         kaaMaxConnCount   = 7,        // 应用的最大连接个数, 默认值: 0 表示无限制
         kaaOnConnLogin    = 8,        // 应用的 OnConnLogin   事件, 连接登录(TRCKOnAppLogin)
         kaaOnConnLogout   = 9,        // 应用的 OnConnLogout  事件, 连接登出(TRCKOnAppLogout)
         kaaOnExecResp     = 10,       // 应用的 OnExecResp    事件, 执行应答(TRCKOnAppResp)
         kaaOnRespCancel   = 11,       // 应用的 OnRespCancel  事件, 应答已取消(TRCKOnAppResp)
         kaaOnRespConfirm  = 12,       // 应用的 OnRespConfirm 事件, 应答已确认(TRCKOnAppResp)
         kaaBaseFuncObj    = 0x10000,  // 应用的函数索引基数: 函数对象
         kaaBaseFuncName   = 0x20000,  // 应用的函数索引基数: 函数名
         kaaBaseConnObj    = 0x40000}; // 应用的连接索引基数: 连接对象

// 应用的状态
enum TRCKAppState
        {kasInactive       = 0,        // 函数未定义
         kasDefining       = 1,        // 函数正在定义
         kasDefined        = 2,        // 函数已定义
         kasClosing        = 3,        // 正在关闭
         kasOpening        = 4,        // 正在打开
         kasOpened         = 5};       // 已打开

// 函数的属性项
enum TRCKFuncAttrib
        {kfaData           = 0,        // 自定义数据
         kfaName           = 1,        // 函数名
         kfaActive         = 2,        // 函数是否已激活
         kfaAppObj         = 3,        // 函数所属应用对象
         kfaRetType        = 4,        // 函数返回值类型
         kfaRetSize        = 5,        // 函数返回值定义尺寸
         kfaCallMode       = 6,        // 回调函数模式
         kfaCallback       = 7,        // 回调函数指针
         kfaParamCount     = 8,        // 函数的参数个数
         kfaFieldCount     = 9,        // 函数的返回字段个数
         kfaNeedConfirm    = 10,       // 函数应答返回是否需要确认
         kfaNeedEncrypt    = 11,       // 函数参数和返回值在通讯中是否需要加密
         kfaBaseParamName  = 0x10000,  // 函数参数索引基数: 参数名
         kfaBaseParamType  = 0x20000,  // 函数参数索引基数: 参数类型
         kfaBaseParamSize  = 0x30000,  // 函数参数索引基数: 参数定义尺寸
         kfaBaseParamIsRef = 0x40000,  // 函数参数索引基数: 参数是否为引用指针
         kfaBaseFieldName  = 0x60000,  // 函数返回字段索引基数: 返回字段名
         kfaBaseFieldType  = 0x70000,  // 函数返回字段索引基数: 返回字段类型
         kfaBaseFieldSize  = 0x80000}; // 函数返回字段索引基数: 返回字段定义尺寸

// 回调函数模式
enum TRCKFuncCallMode
        {kfcmNone          = 0,        // 无, 请求通过 OnExecResp 事件返回
         kfcmFixed         = 1,        // 固定的回调模式(TRCKDoFixed类型)
         kfcmCdecl         = 2,        // C 语言调用协议
         kfcmStdcall       = 3,        // API 标准调用协议
         kfcmIDCdecl       = 4,        // 带 AResp 参数的 C 语言调用协议
         kfcmIDStdcall     = 5};       // 带 AResp 参数的 API 标准调用协议

// 连接的属性项
enum TRCKConnAttrib
        {kcaError          = 0,        // 错误信息
         kcaData           = 1,        // 自定义数据
         kcaType           = 2,        // 连接的类型
         kcaState          = 3,        // 连接的状态
         kcaSlotObj        = 4,        // 连接绑定的通讯槽对象(用于TRCKSlotMethods方法列表)
         kcaCanLogin       = 5,        // 连接是否能够登录对端应用, 默认值: (Type == kctTCPClient)
         kcaCanBindApp     = 6,        // 连接是否能够绑定应用, 默认值: (Type == kctTCPSrvClient)
         kcaBindAppObj     = 7,        // 连接绑定的应用对象, 默认值: NULL
         kcaIsSyncLink     = 8,        // 通讯槽对象打开成功后是否同步建立连接, 默认值: (Type == kctTCPClient)
         kcaSlotTimeout    = 9,        // 通讯槽对象的打开超时(单位: 毫秒), 默认值: 30000
         kcaSlotMaxSize    = 10,       // 通讯槽对象的数据包最大长度, 默认值: 8192
         kcaSendQueueSize  = 11,       // 连接的 RCKConnSendData 发送队列尺寸, 默认值: 256
         kcaTimeout        = 12,       // 连接的操作超时(单位: 毫秒), 默认值: 30000
         kcaAppName        = 13,       // 登录对端应用名
         kcaAppPass        = 14,       // 登录对端应用密码
         kcaCurrAddr       = 15,       // 连接的本地地址
         kcaCurrPort       = 16,       // 连接的本地端口号
         kcaPeerAddr       = 17,       // 连接的对端地址
         kcaPeerPort       = 18,       // 连接的对端端口号
         kcaLastTick       = 19,       // 连接的最后一次收发数据时 tick
         kcaFuncCount      = 20,       // 已加载对端应用的函数个数, 默认值: -1 表示未加载
         kcaKeepTimeout    = 21,       // 连接的心跳检测超时时间(单位: 毫秒), 默认值: 30000
         kcaKeepInterval   = 22,       // 连接的心跳检测重试间隔(单位: 毫秒), 默认值: 10000
         kcaKeepRetryTimes = 23,       // 连接的心跳检测重试次数, 默认值: 3
         kcaOnConnect      = 24,       // 连接的 OnConnect     事件, 连接成功(TRCKOnObjEvent)
         kcaOnDisconnect   = 25,       // 连接的 OnDisconnect  事件, 断开连接(TRCKOnObjEvent)
         kcaOnLogin        = 26,       // 连接的 OnLogin       事件, 登录对端应用(TRCKOnObjEvent)
         kcaOnLogout       = 27,       // 连接的 OnLogout      事件, 登出对端应用(TRCKOnObjEvent)
         kcaOnCmdReturn    = 28,       // 连接的 OnCmdReturn   事件, 命令返回(TRCKOnCmdReturn)
         kcaOnRecvData     = 29,       // 连接的 OnRecvData    事件, 接收数据(TRCKOnRecvData)
         kcaBaseSlotExt    = 0x10000,  // 通讯槽对象的扩展属性基数: 扩展属性项
         kcaBaseFuncName   = 0x20000}; // 已加载对端应用的函数索引基数: 函数名

// 连接的类型
enum TRCKConnType
        {kctUnknown        = 0,        // (未知)
         kctTCPClient      = 1,        // TCP 客户端
         kctTCPSrvClient   = 2,        // TCP 服务端的客户连接
         kctSHMClient      = 3,        // SHM 客户端(共享内存通讯)
         kctSHMSrvClient   = 4,        // SHM 服务端的客户连接(共享内存通讯)
         // ... ...                    // 可以根据 slot 通讯方式自定义扩充
         };

// 连接的状态
enum TRCKConnState
        {kcsInactive       = 0,        // 未打开
         kcsClosing        = 1,        // 正在关闭
         kcsOpening        = 2,        // 正在打开
         kcsOpened         = 3,        // 已经打开
         kcsLogouting      = 4,        // 正在登出对端应用
         kcsLogging        = 5,        // 正在登录对端应用
         kcsLogged         = 6,        // 已登录对端应用
         kcsLoading        = 7,        // 正在加载对端应用函数列表
         kcsLoaded         = 8};       // 已加载对端应用函数列表

// 命令的属性项
enum TRCKCmdAttrib
        {kmaData           = 0,        // 自定义数据
         kmaName           = 1,        // 命令的函数名
         kmaState          = 2,        // 命令的状态
         kmaConnObj        = 3,        // 命令的连接对象
         kmaRetType        = 4,        // 命令的返回值类型
         kmaRetSize        = 5,        // 命令的返回值定义尺寸
         kmaParamCount     = 6,        // 命令的参数个数
         kmaFieldCount     = 7,        // 命令的返回字段个数
         kmaExecResult     = 8,        // 命令的执行返回结果(值参见 TRCKCmdResult)
         kmaEncrypted      = 9,        // 命令的参数和返回值在通讯中是否加密
         kmaAppIsValid     = 10,       // 命令已开始的应用是否有效
         kmaBaseParamName  = 0x10000,  // 命令的参数索引基数: 参数名
         kmaBaseParamType  = 0x20000,  // 命令的参数索引基数: 参数类型
         kmaBaseParamSize  = 0x30000,  // 命令的参数索引基数: 参数定义尺寸
         kmaBaseFieldName  = 0x60000,  // 命令的返回字段索引基数: 返回字段名
         kmaBaseFieldType  = 0x70000,  // 命令的返回字段索引基数: 返回字段类型
         kmaBaseFieldSize  = 0x80000}; // 命令的返回字段索引基数: 返回字段定义尺寸

// 命令返回结果
enum TRCKCmdResult
        {kmrFailure        = 0,        // 失败
         kmrSuccess        = 1,        // 成功
         kmrException      = 2,        // 异常
         kmrBreak          = 3};       // 中止

// 命令状态
enum TRCKCmdState
        {kmsIdle           = 0,        // 空闲
         kmsEnding         = 1,        // 正在结束
         kmsBeginning      = 2,        // 正在开始
         kmsBegun          = 3,        // 已开始
         kmsExecuting      = 4,        // 正在执行
         kmsExecuted       = 5,        // 执行结束, 已返回
         kmsCanceled       = 6};       // 已取消(如: 超时等等)

// 应答状态
enum TRCKRespState
        {krsIdle           = 0,        // 空闲
         krsExecuting      = 1,        // 正在执行
         krsWaitSend       = 2,        // 应答已执行, 正在等待发送
         krsSending        = 3,        // 应答已执行, 正在发送
         krsSent           = 4,        // 应答已执行, 应答发送完成
         krsConfirmed      = 5,        // 应答已确认接收
         krsCanceled       = 6};       // 应答已取消

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/* 回调函数类型定义 */

// 固定的回调模式
typedef void  (__stdcall *TRCKDoFixed)(void* AFuncObj, void* AResp);

// 对象事件的回调函数类型
typedef void  (__stdcall *TRCKOnObjEvent)(void* AObject);

// 应用连接登录事件的回调函数类型(OnConnLogin)
typedef void  (__stdcall *TRCKOnAppLogin)(void* AppObj, void* AConnObj, bool& AIsRefused);

// 应用连接登出事件的回调函数类型(OnConnLogout)
typedef void  (__stdcall *TRCKOnAppLogout)(void* AppObj, void* AConnObj);

// 应用应答事件的回调函数类型(OnExecResp, OnRespCancel, OnRespConfirm)
typedef void  (__stdcall *TRCKOnAppResp)(void* AppObj, void* AFuncObj, void* AResp);

// 连接命令返回事件的回调函数类型(AResult 值参见 TRCKCmdResult)
typedef void  (__stdcall *TRCKOnCmdReturn)(void* AConnObj, void* ACmdObj, long AResult);

// 接收自定义数据的回调函数类型
typedef void  (__stdcall *TRCKOnRecvData)(void* AConnObj, const void* AData, long ASize);

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/* 接口相关函数 */

// 接口初始化/释放函数
void     __stdcall RCKInitialize();
void     __stdcall RCKUninitialize();

// 接口版本信息, 格式: "x.x.x.x (build yyyy.mm.dd)"
// AVersion    返回版本号, 如: 0x0708090A 表示 7.8.9.10
char*    __stdcall RCKGetVersion(long* AVersion);

// 取当前操作的最后错误码(注: 用于返回值非错误码的函数, 如 RCKConnCreate 等等)
long     __stdcall RCKGetLastError();

// 在回调函数中取当前应用线程的应答
void*    __stdcall RCKGetCurrResp();

// 根据应用名取应用对象
void*    __stdcall RCKGetAppObj(const char* AName);

// 取接口属性
// (返回值为属性值, ARetCode 为失败的返回码, 允许为空, 当字符串类型成功时为值尺寸)
long     __stdcall RCKGetInt(long Attrib, long* ARetCode);
void*    __stdcall RCKGetObj(long Attrib, long* ARetCode);
char*    __stdcall RCKGetStr(long Attrib, long* ARetCode);

// 设置接口属性
long     __stdcall RCKSetInt(long Attrib, long  AValue);
long     __stdcall RCKSetObj(long Attrib, void* AValue);
long     __stdcall RCKSetStr(long Attrib, const char* AValue, long ASize);

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/* Application 的相关函数 */

// 创建/释放应用
void*    __stdcall RCKAppCreate(const char* AName, const char* APassword);
void     __stdcall RCKAppFree(void* AppObj);

// 开始/结束应用的函数定义
long     __stdcall RCKAppFuncBegin(void* AppObj);
long     __stdcall RCKAppFuncEnd(void* AppObj);

// 根据函数名取应用的函数对象
void*    __stdcall RCKAppFuncObj(void* AppObj, const char* AName);

// 打开/关闭应用/强制注销应用的连接
long     __stdcall RCKAppOpen(void* AppObj);
long     __stdcall RCKAppClose(void* AppObj);
long     __stdcall RCKAppLogout(void* AppObj, void* AConnObj);

// 取应用属性
// (返回值为属性值, ARetCode 为失败的返回码, 允许为空, 当字符串类型成功时为值尺寸)
long     __stdcall RCKAppGetInt(void* AppObj, long Attrib, long* ARetCode);
void*    __stdcall RCKAppGetObj(void* AppObj, long Attrib, long* ARetCode);
char*    __stdcall RCKAppGetStr(void* AppObj, long Attrib, long* ARetCode);

// 设置应用属性
long     __stdcall RCKAppSetInt(void* AppObj, long Attrib, long  AValue);
long     __stdcall RCKAppSetObj(void* AppObj, long Attrib, void* AValue);
long     __stdcall RCKAppSetStr(void* AppObj, long Attrib,
                          const char* AValue, long ASize);

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/* Function 的相关函数 */

// 创建/释放 Function
void*    __stdcall RCKFuncCreate(void* AppObj, long ACallMode, void* ACallback,
                           const char* AName,  long ARetType,  long  ARetSize);
void     __stdcall RCKFuncFree(void* AFuncObj);

// 添加 Function 参数/返回字段
long     __stdcall RCKFuncAddParam(void* AFuncObj,    const char* AName,
                                   long  AType, long ASize, bool  AIsRef);
long     __stdcall RCKFuncAddField(void* AFuncObj,    const char* AName,
                                   long  AType,             long  ASize);

// 取 Function 参数名索引/返回字段名索引
long     __stdcall RCKFuncParamIndex(void* AFuncObj, const char* AName);
long     __stdcall RCKFuncFieldIndex(void* AFuncObj, const char* AName);

// 取 Function 属性
// (返回值为属性值, ARetCode 为失败的返回码, 允许为空, 当字符串类型成功时为值尺寸)
long     __stdcall RCKFuncGetInt(void* AFuncObj, long Attrib, long* ARetCode);
void*    __stdcall RCKFuncGetObj(void* AFuncObj, long Attrib, long* ARetCode);
char*    __stdcall RCKFuncGetStr(void* AFuncObj, long Attrib, long* ARetCode);

// 设置 Function 属性
long     __stdcall RCKFuncSetInt(void* AFuncObj, long Attrib, long  AValue);
long     __stdcall RCKFuncSetObj(void* AFuncObj, long Attrib, void* AValue);
long     __stdcall RCKFuncSetStr(void* AFuncObj, long Attrib,
                           const char* AValue,   long ASize);

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/* Connection 的相关函数 */

// 创建/释放连接(注: ASlotObj 必须非空且唯一, ASlotMethods 必须非空)
void*    __stdcall RCKConnCreate(long AType, void* ASlotObj,
                            const TRCKSlotMethods* ASlotMethods);
void     __stdcall RCKConnFree(void* AConnObj);

// 打开/关闭连接
long     __stdcall RCKConnOpen(void* AConnObj);
long     __stdcall RCKConnClose(void* AConnObj);

// 登录/登出对端应用
long     __stdcall RCKConnLogin(void* AConnObj);
long     __stdcall RCKConnLogout(void* AConnObj);

// 加载对端应用的函数列表
long     __stdcall RCKConnLoad(void* AConnObj);

// 发送数据(参数 ANeedPack 表示数据是否需要压缩发送)
long     __stdcall RCKConnSendData(void* AConnObj, const void* AData,
                                   long  ASize,          bool  ANeedPack);

// 取连接属性
// (返回值为属性值, ARetCode 为失败的返回码, 允许为空, 当字符串类型成功时为值尺寸)
long     __stdcall RCKConnGetInt(void* AConnObj, long Attrib, long* ARetCode);
void*    __stdcall RCKConnGetObj(void* AConnObj, long Attrib, long* ARetCode);
char*    __stdcall RCKConnGetStr(void* AConnObj, long Attrib, long* ARetCode);

// 设置连接属性
long     __stdcall RCKConnSetInt(void* AConnObj, long Attrib, long  AValue);
long     __stdcall RCKConnSetObj(void* AConnObj, long Attrib, void* AValue);
long     __stdcall RCKConnSetStr(void* AConnObj, long Attrib,
                           const char* AValue,   long ASize);

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/* Command 的相关函数 */

// 创建/释放命令
void*    __stdcall RCKCmdCreate();
void     __stdcall RCKCmdFree(void* ACmdObj);

// 开始/结束命令
long     __stdcall RCKCmdBegin(void* ACmdObj, const char* AName);
long     __stdcall RCKCmdEnd(void* ACmdObj);

// 重新开始/执行命令
long     __stdcall RCKCmdRestart(void* ACmdObj);
long     __stdcall RCKCmdExecute(void* ACmdObj, unsigned long ATimeout);

// 取命令属性
// (返回值为属性值, ARetCode 为失败的返回码, 允许为空, 当字符串类型成功时为值尺寸)
long     __stdcall RCKCmdGetInt(void* ACmdObj, long Attrib, long* ARetCode);
void*    __stdcall RCKCmdGetObj(void* ACmdObj, long Attrib, long* ARetCode);
char*    __stdcall RCKCmdGetStr(void* ACmdObj, long Attrib, long* ARetCode);

// 设置命令属性
long     __stdcall RCKCmdSetInt(void* ACmdObj, long Attrib, long  AValue);
long     __stdcall RCKCmdSetObj(void* ACmdObj, long Attrib, void* AValue);
long     __stdcall RCKCmdSetStr(void* ACmdObj, long Attrib,
                          const char* AValue,  long ASize);

// 取当前命令的各类型返回值
// (ARetCode 为失败的返回码, 允许为空, 当字符串或结构类型成功时为值尺寸)
char*    __stdcall RCKCmdRetStr(void* ACmdObj, long* ARetCode);
long     __stdcall RCKCmdRetInt(void* ACmdObj, long* ARetCode);
bool     __stdcall RCKCmdRetBool(void* ACmdObj, long* ARetCode);
double   __stdcall RCKCmdRetFloat(void* ACmdObj, long* ARetCode);
void*    __stdcall RCKCmdRetStruct(void* ACmdObj, long* ARetCode);
__int64  __stdcall RCKCmdRetInt64(void* ACmdObj, long* ARetCode);
double   __stdcall RCKCmdRetDate(void* ACmdObj, long* ARetCode);
long     __stdcall RCKCmdRetCustom(void* ACmdObj, void* AValue, long ASize);

// 清除当前命令参数值/取当前命令的参数名索引
long     __stdcall RCKCmdParamClear(void* ACmdObj);
long     __stdcall RCKCmdParamIndex(void* ACmdObj, const char* AName);

// 根据参数索引设置当前命令的各类型参数值
long     __stdcall RCKCmdParamByStr(void* ACmdObj, long AIndex,
                              const char* AValue,  long ASize);
long     __stdcall RCKCmdParamByInt(void* ACmdObj, long AIndex, long AValue);
long     __stdcall RCKCmdParamByBool(void* ACmdObj, long AIndex, bool AValue);
long     __stdcall RCKCmdParamByFloat(void* ACmdObj, long AIndex, double AValue);
long     __stdcall RCKCmdParamByStruct(void* ACmdObj, long AIndex, void* AValue);
long     __stdcall RCKCmdParamByInt64(void* ACmdObj, long AIndex, __int64 AValue);
long     __stdcall RCKCmdParamByDate(void* ACmdObj, long AIndex, double AValue);
long     __stdcall RCKCmdParamByCustom(void* ACmdObj, long AIndex,
                                 const void* AValue,  long ASize);

// 根据参数名设置当前命令的各类型参数值
long     __stdcall RCKCmdParamByStr_(void* ACmdObj, const char* AName,
                               const char* AValue,        long  ASize);
long     __stdcall RCKCmdParamByInt_(void* ACmdObj, const char* AName, long AValue);
long     __stdcall RCKCmdParamByBool_(void* ACmdObj, const char* AName, bool AValue);
long     __stdcall RCKCmdParamByFloat_(void* ACmdObj, const char* AName, double AValue);
long     __stdcall RCKCmdParamByStruct_(void* ACmdObj, const char* AName, void* AValue);
long     __stdcall RCKCmdParamByInt64_(void* ACmdObj, const char* AName, __int64 AValue);
long     __stdcall RCKCmdParamByDate_(void* ACmdObj, const char* AName, double AValue);
long     __stdcall RCKCmdParamByCustom_(void* ACmdObj, const char* AName,
                                  const void* AValue,        long  ASize);

// 取当前命令的返回字段名索引/字段值是否为空(ARetCode 为失败的返回码, 允许为空)
long     __stdcall RCKCmdFieldIndex(void* ACmdObj, const char* AName);
bool     __stdcall RCKCmdFieldIsNull(void* ACmdObj, long AIndex, long* ARetCode);
bool     __stdcall RCKCmdFieldIsNull_(void* ACmdObj, const char* AName, long* ARetCode);

// 根据字段索引取当前命令的各类型字段值
// (ARetCode 为失败的返回码, 允许为空, 当字符串或结构类型成功时为值尺寸)
char*    __stdcall RCKCmdFieldStr(void* ACmdObj, long AIndex, long* ARetCode);
long     __stdcall RCKCmdFieldInt(void* ACmdObj, long AIndex, long* ARetCode);
bool     __stdcall RCKCmdFieldBool(void* ACmdObj, long AIndex, long* ARetCode);
double   __stdcall RCKCmdFieldFloat(void* ACmdObj, long AIndex, long* ARetCode);
void*    __stdcall RCKCmdFieldStruct(void* ACmdObj, long AIndex, long* ARetCode);
__int64  __stdcall RCKCmdFieldInt64(void* ACmdObj, long AIndex, long* ARetCode);
double   __stdcall RCKCmdFieldDate(void* ACmdObj, long AIndex, long* ARetCode);
long     __stdcall RCKCmdFieldCustom(void* ACmdObj, long AIndex,
                                     void* AValue,  long ASize);

// 根据字段名取当前命令的各类型字段值
// (ARetCode 为失败的返回码, 允许为空, 当字符串或结构类型成功时为值尺寸)
char*    __stdcall RCKCmdFieldStr_(void* ACmdObj, const char* AName, long* ARetCode);
long     __stdcall RCKCmdFieldInt_(void* ACmdObj, const char* AName, long* ARetCode);
bool     __stdcall RCKCmdFieldBool_(void* ACmdObj, const char* AName, long* ARetCode);
double   __stdcall RCKCmdFieldFloat_(void* ACmdObj, const char* AName, long* ARetCode);
void*    __stdcall RCKCmdFieldStruct_(void* ACmdObj, const char* AName, long* ARetCode);
__int64  __stdcall RCKCmdFieldInt64_(void* ACmdObj, const char* AName, long* ARetCode);
double   __stdcall RCKCmdFieldDate_(void* ACmdObj, const char* AName, long* ARetCode);
long     __stdcall RCKCmdFieldCustom_(void* ACmdObj, const char* AName,
                                      void* AValue,        long  ASize);

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/* Response 的相关函数 */

// 取应答的连接对象/函数对象/状态
void*    __stdcall RCKRespConnObj(void* AResp);
void*    __stdcall RCKRespFuncObj(void* AResp);
long     __stdcall RCKRespState(void* AResp);

// 取应答的各类型返回值
// (ARetCode 为失败的返回码, 允许为空, 当字符串或结构类型成功时为值尺寸)
char*    __stdcall RCKRespRetStr(void* AResp, long* ARetCode);
long     __stdcall RCKRespRetInt(void* AResp, long* ARetCode);
bool     __stdcall RCKRespRetBool(void* AResp, long* ARetCode);
double   __stdcall RCKRespRetFloat(void* AResp, long* ARetCode);
void*    __stdcall RCKRespRetStruct(void* AResp, long* ARetCode);
__int64  __stdcall RCKRespRetInt64(void* AResp, long* ARetCode);
double   __stdcall RCKRespRetDate(void* AResp, long* ARetCode);
long     __stdcall RCKRespRetCustom(void* AResp, void* AValue, long ASize);

// 根据索引取应答的各类型参数值
// (ARetCode 为失败的返回码, 允许为空, 当字符串或结构类型成功时为值尺寸)
char*    __stdcall RCKRespParamStr(void* AResp, long AIndex, long* ARetCode);
long     __stdcall RCKRespParamInt(void* AResp, long AIndex, long* ARetCode);
bool     __stdcall RCKRespParamBool(void* AResp, long AIndex, long* ARetCode);
double   __stdcall RCKRespParamFloat(void* AResp, long AIndex, long* ARetCode);
void*    __stdcall RCKRespParamStruct(void* AResp, long AIndex, long* ARetCode);
__int64  __stdcall RCKRespParamInt64(void* AResp, long AIndex, long* ARetCode);
double   __stdcall RCKRespParamDate(void* AResp, long AIndex, long* ARetCode);
long     __stdcall RCKRespParamCustom(void* AResp,  long AIndex,
                                      void* AValue, long ASize);

// 根据参数名取应答的各类型参数值
// (ARetCode 为失败的返回码, 允许为空, 当字符串或结构类型成功时为值尺寸)
char*    __stdcall RCKRespParamStr_(void* AResp, const char* AName, long* ARetCode);
long     __stdcall RCKRespParamInt_(void* AResp, const char* AName, long* ARetCode);
bool     __stdcall RCKRespParamBool_(void* AResp, const char* AName, long* ARetCode);
double   __stdcall RCKRespParamFloat_(void* AResp, const char* AName, long* ARetCode);
void*    __stdcall RCKRespParamStruct_(void* AResp, const char* AName, long* ARetCode);
__int64  __stdcall RCKRespParamInt64_(void* AResp, const char* AName, long* ARetCode);
double   __stdcall RCKRespParamDate_(void* AResp, const char* AName, long* ARetCode);
long     __stdcall RCKRespParamCustom_(void* AResp, const char* AName,
                                       void* AValue,      long  ASize);

// 根据索引取应答的各类型字段返回值
// (ARetCode 为失败的返回码, 允许为空, 当字符串或结构类型成功时为值尺寸)
char*    __stdcall RCKRespFieldStr(void* AResp, long AIndex, long* ARetCode);
long     __stdcall RCKRespFieldInt(void* AResp, long AIndex, long* ARetCode);
bool     __stdcall RCKRespFieldBool(void* AResp, long AIndex, long* ARetCode);
double   __stdcall RCKRespFieldFloat(void* AResp, long AIndex, long* ARetCode);
void*    __stdcall RCKRespFieldStruct(void* AResp, long AIndex, long* ARetCode);
__int64  __stdcall RCKRespFieldInt64(void* AResp, long AIndex, long* ARetCode);
double   __stdcall RCKRespFieldDate(void* AResp, long AIndex, long* ARetCode);
long     __stdcall RCKRespFieldCustom(void* AResp,  long AIndex,
                                      void* AValue, long ASize);

// 根据字段名取应答的各类型字段返回值
// (ARetCode 为失败的返回码, 允许为空, 当字符串或结构类型成功时为值尺寸)
char*    __stdcall RCKRespFieldStr_(void* AResp, const char* AName, long* ARetCode);
long     __stdcall RCKRespFieldInt_(void* AResp, const char* AName, long* ARetCode);
bool     __stdcall RCKRespFieldBool_(void* AResp, const char* AName, long* ARetCode);
double   __stdcall RCKRespFieldFloat_(void* AResp, const char* AName, long* ARetCode);
void*    __stdcall RCKRespFieldStruct_(void* AResp, const char* AName, long* ARetCode);
__int64  __stdcall RCKRespFieldInt64_(void* AResp, const char* AName, long* ARetCode);
double   __stdcall RCKRespFieldDate_(void* AResp, const char* AName, long* ARetCode);
long     __stdcall RCKRespFieldCustom_(void* AResp, const char* AName,
                                       void* AValue,      long  ASize);

// 设置应答的各类型返回值
long     __stdcall RCKRespRetByStr(void* AResp, const char* AValue, long ASize);
long     __stdcall RCKRespRetByInt(void* AResp, long AValue);
long     __stdcall RCKRespRetByBool(void* AResp, bool AValue);
long     __stdcall RCKRespRetByFloat(void* AResp, double AValue);
long     __stdcall RCKRespRetByStruct(void* AResp, void* AValue);
long     __stdcall RCKRespRetByInt64(void* AResp, __int64 AValue);
long     __stdcall RCKRespRetByDate(void* AResp, double AValue);
long     __stdcall RCKRespRetByCustom(void* AResp, const void* AValue, long ASize);

// 根据索引设置应答的各类型字段返回值
long     __stdcall RCKRespFieldByStr(void* AResp,  long AIndex,
                               const char* AValue, long ASize);
long     __stdcall RCKRespFieldByInt(void* AResp, long AIndex, long AValue);
long     __stdcall RCKRespFieldByBool(void* AResp, long AIndex, bool AValue);
long     __stdcall RCKRespFieldByFloat(void* AResp, long AIndex, double AValue);
long     __stdcall RCKRespFieldByStruct(void* AResp, long AIndex, void* AValue);
long     __stdcall RCKRespFieldByInt64(void* AResp, long AIndex, __int64 AValue);
long     __stdcall RCKRespFieldByDate(void* AResp, long AIndex, double AValue);
long     __stdcall RCKRespFieldByCustom(void* AResp,  long AIndex,
                                  const void* AValue, long ASize);

// 根据字段名设置应答的各类型字段返回值
long     __stdcall RCKRespFieldByStr_(void* AResp, const char* AName,
                                const char* AValue,      long  ASize);
long     __stdcall RCKRespFieldByInt_(void* AResp, const char* AName, long AValue);
long     __stdcall RCKRespFieldByBool_(void* AResp, const char* AName, bool AValue);
long     __stdcall RCKRespFieldByFloat_(void* AResp, const char* AName, double AValue);
long     __stdcall RCKRespFieldByStruct_(void* AResp, const char* AName, void* AValue);
long     __stdcall RCKRespFieldByInt64_(void* AResp, const char* AName, __int64 AValue);
long     __stdcall RCKRespFieldByDate_(void* AResp, const char* AName, double AValue);
long     __stdcall RCKRespFieldByCustom_(void* AResp, const char* AName,
                                   const void* AValue,      long  ASize);

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/* Fields 的相关函数 */

// 创建/释放字段集
void*    __stdcall RCKFieldsCreate();
void     __stdcall RCKFieldsFree(void* AFields);

// 添加字段定义/删除指定索引的字段及定义
long     __stdcall RCKFieldDefsAdd(void* AFields, const char* AName,
                                   long  AType,         long  ASize);
void     __stdcall RCKFieldDefsDelete(void* AFields, long AIndex);

// 清除/拷贝/输出字段定义集/取字段定义集的数据尺寸
void     __stdcall RCKFieldDefsClear(void* AFields);
long     __stdcall RCKFieldDefsAssign(void* AFields, const void* ADefs, long ASize);
void*    __stdcall RCKFieldDefsOutput(void* AFields, long* ARetSize);
long     __stdcall RCKFieldDefsSize(const void* AFieldDefs);

// 清除/拷贝/输出字段集的数据/取字段集的数据尺寸
void     __stdcall RCKFieldsClear(void* AFields);
long     __stdcall RCKFieldsAssign(void* AFields, const void* AData, long ASize);
void*    __stdcall RCKFieldsOutput(void* AFields, long* ARetSize);
long     __stdcall RCKFieldsSize(void* AFields);

// 取字段个数/取字段名所在索引
long     __stdcall RCKFieldCount(void* AFields);
long     __stdcall RCKFieldIndex(void* AFields, const char* AName);

// 取索引字段名/类型/定义尺寸/值尺寸
char*    __stdcall RCKFieldName(void* AFields, long AIndex);
long     __stdcall RCKFieldType(void* AFields, long AIndex);
long     __stdcall RCKFieldDefSize(void* AFields, long AIndex);
long     __stdcall RCKFieldSize(void* AFields, long AIndex);

// 判断索引字段是否为空(ARetCode 为失败的返回码, 允许为空)
bool     __stdcall RCKFieldIsNull(void* AFields, long AIndex, long* ARetCode);
bool     __stdcall RCKFieldIsNull_(void* AFields, const char* AName, long* ARetCode);

// 取索引字段的各类型值
// (ARetCode 为失败的返回码, 允许为空, 当字符串或结构类型成功时为值尺寸)
char*    __stdcall RCKFieldAsStr(void* AFields, long AIndex, long* ARetCode);
long     __stdcall RCKFieldAsInt(void* AFields, long AIndex, long* ARetCode);
bool     __stdcall RCKFieldAsBool(void* AFields, long AIndex, long* ARetCode);
double   __stdcall RCKFieldAsFloat(void* AFields, long AIndex, long* ARetCode);
void*    __stdcall RCKFieldAsStruct(void* AFields, long AIndex, long* ARetCode);
__int64  __stdcall RCKFieldAsInt64(void* AFields, long AIndex, long* ARetCode);
double   __stdcall RCKFieldAsDate(void* AFields, long AIndex, long* ARetCode);
long     __stdcall RCKFieldGetCustom(void* AFields, long AIndex,
                                     void* AValue,  long ASize);

// 取字段名字段的各类型值
// (ARetCode 为失败的返回码, 允许为空, 当字符串或结构类型成功时为值尺寸)
char*    __stdcall RCKFieldAsStr_(void* AFields, const char* AName, long* ARetCode);
long     __stdcall RCKFieldAsInt_(void* AFields, const char* AName, long* ARetCode);
bool     __stdcall RCKFieldAsBool_(void* AFields, const char* AName, long* ARetCode);
double   __stdcall RCKFieldAsFloat_(void* AFields, const char* AName, long* ARetCode);
void*    __stdcall RCKFieldAsStruct_(void* AFields, const char* AName, long* ARetCode);
__int64  __stdcall RCKFieldAsInt64_(void* AFields, const char* AName, long* ARetCode);
double   __stdcall RCKFieldAsDate_(void* AFields, const char* AName, long* ARetCode);
long     __stdcall RCKFieldGetCustom_(void* AFields, const char* AName,
                                      void* AValue,        long  ASize);

// 设置索引字段的类型值
long     __stdcall RCKFieldByStr(void* AFields, long AIndex,
                           const char* AValue,  long ASize);
long     __stdcall RCKFieldByInt(void* AFields, long AIndex, long AValue);
long     __stdcall RCKFieldByBool(void* AFields, long AIndex, bool AValue);
long     __stdcall RCKFieldByFloat(void* AFields, long AIndex, double AValue);
long     __stdcall RCKFieldByStruct(void* AFields, long AIndex, void* AValue);
long     __stdcall RCKFieldByInt64(void* AFields, long AIndex, __int64 AValue);
long     __stdcall RCKFieldByDate(void* AFields, long AIndex, double AValue);
long     __stdcall RCKFieldSetCustom(void* AFields, long AIndex,
                               const void* AValue,  long ASize);

// 设置字段名字段的类型值
long     __stdcall RCKFieldByStr_(void* AFields, const char* AName,
                            const char* AValue,        long  ASize);
long     __stdcall RCKFieldByInt_(void* AFields, const char* AName, long AValue);
long     __stdcall RCKFieldByBool_(void* AFields, const char* AName, bool AValue);
long     __stdcall RCKFieldByFloat_(void* AFields, const char* AName, double AValue);
long     __stdcall RCKFieldByStruct_(void* AFields, const char* AName, const void* AValue);
long     __stdcall RCKFieldByInt64_(void* AFields, const char* AName, __int64 AValue);
long     __stdcall RCKFieldByDate_(void* AFields, const char* AName, double AValue);
long     __stdcall RCKFieldSetCustom_(void* AFields, const char* AName,
                                const void* AValue,        long  ASize);

}

#endif


4. RC 的自环接口定义(注: 内部实现 RCK 通讯槽接口)
    自环接口用于进程内通过 Command 调用 Application 函数, 便于输出接口统一。
    参见 <RC4SL.h> 文件

// =======================================
// Unit   : RC for self-loop
// Version: 4.0.0.0 (build 2013.08.18)
// Author : Kyee Ye
// Email  : kyee_ye(at)126.com
// Copyright (C) Kyee workroom
// =======================================

#ifndef _RC4SL_H_
#define _RC4SL_H_

#include "RCKernel.h"
using namespace RCKernel;

#ifdef _WIN64
#pragma comment(lib, "RC4SL64.lib")
#else
#pragma comment(lib, "RC4SL32.lib")
#endif

namespace RC4SL
{

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/* 常量定义 */

// 返回值及错误码
// 见 RCKSlot.h 中的 TRCKResult 定义

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/* 接口相关函数 */

// 接口初始化/释放函数
void  __stdcall SLInitialize();
void  __stdcall SLUninitialize();

// 接口版本信息, 格式: "x.x.x.x (build yyyy.mm.dd)"
// AVersion    返回版本号, 如: 0x0708090A 表示 7.8.9.10
char* __stdcall SLGetVersion(long* AVersion);

// 取当前操作的最后错误码(注: 用于返回值非错误码的函数)
long  __stdcall SLGetLastError();

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/* SL 的相关函数 */

// 创建 SL 连接, 返回 RCKConnCreate 创建的对象
// 注:  SL 连接的释放调用 RCKConnFree 即可
void* __stdcall SLCreate();

// 取 SL 连接个数/指定索引的连接对象
long  __stdcall SLGetCount();
void* __stdcall SLGetConnObj(long AIndex);

// 断开 SL 连接(注: 用于测试 Slot 的 OnDisconnect 事件)
long  __stdcall SLDisconnect(void* ASlotObj);

}

#endif


 

5. RC 的 TCP 接口定义(注: 内部实现 RCK 通讯槽接口)
    参见 <RC4TCP.h> 文件

// =======================================
// Unit   : RC for TCP
// Version: 4.0.0.0 (build 2013.09.09)
// Author : Kyee Ye
// Email  : kyee_ye(at)126.com
// Copyright (C) Kyee workroom
// =======================================

#ifndef _RC4TCP_H_
#define _RC4TCP_H_

#include "RCKernel.h"
using namespace RCKernel;

#ifdef _WIN64
#pragma comment(lib, "RC4TCP64.lib")
#else
#pragma comment(lib, "RC4TCP32.lib")
#endif

namespace RC4TCP
{

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/* 常量定义 */

// 返回值及错误码
// 见 RCKSlot.h 中的 TRCKResult 定义

// 接口的属性项
enum TTCPAttrib
        {taVersion         = 0,        // 接口版本信息, 格式: "x.x.x.x (build yyyy.mm.dd)"
         taServerCount     = 1,        // TCP 服务端个数
         taRecvThreads     = 2,        // 所有客户端的接收线程最大个数, 默认值: 8
         taCacheThreads    = 3,        // 所有客户端的接收线程缓冲池尺寸, 默认值: 8
         taBaseServer      = 0x10000}; // 服务端索引基数: 服务端对象

// 服务端的属性项
enum TTCPServerAttrib
        {tsaError          = 0,        // 打开服务失败返回的错误信息
         tsaData           = 1,        // 自定义数据
         tsaAddr           = 2,        // 服务端的绑定IP地址, 默认值: ""
         tsaPort           = 3,        // 服务端的侦听端口号, 默认值: 0
         tsaState          = 4,        // 服务端的状态
         tsaLinger         = 5,        // TCP 句柄关闭后的拖延时长(秒), 默认值: 0
         tsaListenQueue    = 6,        // 服务端的侦听连接队列尺寸, 默认值: 5
         tsaRecvThreads    = 7,        // 接收线程最大个数, 默认值: 8
         tsaCacheThreads   = 8,        // 接收线程缓冲池尺寸, 默认值: 8
         tsaMaxClientCount = 9,        // 服务端连接的最大客户端个数, 默认值: 0 表示无限制
         tsaSrvClientCount = 10,       // 当前服务已连接的客户端个数
         tsaCanLogin       = 11,       // 连接是否能够登录对端应用, 默认值: false
         tsaCanBindApp     = 12,       // 连接是否能够绑定应用, 默认值: true
         tsaSendMaxSize    = 13,       // 通讯槽对象的发送整个包最大长度, 默认值: 8192
         tsaSendQueueSize  = 14,       // 连接的 RCKConnSendData 发送队列尺寸, 默认值: 256
         tsaTimeout        = 15,       // 连接的操作超时(单位: 毫秒), 默认值: 30000
         tsaKeepTimeout    = 16,       // 连接的心跳检测超时时间(单位: 毫秒), 默认值: 30000
         tsaKeepInterval   = 17,       // 连接的心跳检测重试间隔(单位: 毫秒), 默认值: 10000
         tsaKeepRetryTimes = 18,       // 连接的心跳检测重试次数, 默认值: 3
         tsaOnListen       = 19,       // 服务的 OnListen        事件, 打开侦听(TRCKOnObjEvent)
         tsaOnDisconnect   = 20,       // 服务的 OnDisconnect    事件, 断开侦听(TRCKOnObjEvent)
         tsaOnAccept       = 21,       // 服务的 OnAccept        事件, 接受连接(TTCPOnAccept), 可以设置连接属性
         tsaOnFreeClt      = 22,       // 服务的 OnFreeClt       事件, 释放连接(TRCKOnObjEvent)
         tsaOnCltConnect   = 23,       // 连接的 OnCltConnect    事件, 连接成功(TRCKOnObjEvent)
         tsaOnCltDisconnect= 24,       // 连接的 OnCltDisconnect 事件, 断开连接(TRCKOnObjEvent)
         tsaOnCltLogin     = 25,       // 连接的 OnCltLogin      事件, 登录对端应用(TRCKOnObjEvent)
         tsaOnCltLogout    = 26,       // 连接的 OnCltLogout     事件, 登出对端应用(TRCKOnObjEvent)
         tsaOnCltCmdReturn = 27,       // 连接的 OnCltCmdReturn  事件, 命令返回(TRCKOnCmdReturn)
         tsaOnCltRecvData  = 28,       // 连接的 OnCltRecvData   事件, 接收数据(TRCKOnRecvData)
         tsaBaseSrvClient  = 0x10000}; // 已连接的客户端索引基数: 客户端对象

// 服务端的状态
enum TTCPServerState
        {tssInactive       = 0,        // 未打开
         tssClosing        = 1,        // 正在关闭
         tssOpening        = 2,        // 正在打开
         tssOpened         = 3};       // 已经打开

// 服务端客户连接的属性项(即是连接通讯槽对象的扩展属性项, kcaBaseSlotExt + Attrib)
enum TTCPSrvCltAttrib
        {tscaData          = 0,        // 自定义数据
         tscaSrvObj        = 1,        // 连接的服务端对象
         tscaIsValid       = 2};       // 连接是否有效

// 客户端的属性项(即是连接通讯槽对象的扩展属性项, kcaBaseSlotExt + Attrib)
enum TTCPClientAttrib
        {tcaError          = 0,        // 打开客户端失败返回的错误信息
         tcaData           = 1,        // 自定义数据
         tcaLinger         = 2};       // TCP 句柄关闭后的拖延时长(秒), 默认值: 0

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/* 接口回调函数类型定义 */

// 服务端接受连接事件的回调函数类型(OnAccept)
typedef void (__stdcall *TTCPOnAccept)(void* ASrvObj, void* AConnObj, bool& AIsRefused);

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/* 接口相关函数 */

// 接口初始化/释放函数
void  __stdcall TCPInitialize();
void  __stdcall TCPUninitialize();

// 接口版本信息, 格式: "x.x.x.x (build yyyy.mm.dd)"
// AVersion    返回版本号, 如: 0x0708090A 表示 7.8.9.10
char* __stdcall TCPGetVersion(long* AVersion);

// 取当前操作的最后错误码(注: 用于返回值非错误码的函数)
long  __stdcall TCPGetLastError();

// 取接口属性
// (返回值为属性值, ARetCode 为失败的返回码, 允许为空, 当字符串类型成功时为值尺寸)
long  __stdcall TCPGetInt(long Attrib, long* ARetCode);
void* __stdcall TCPGetObj(long Attrib, long* ARetCode);
char* __stdcall TCPGetStr(long Attrib, long* ARetCode);

// 设置接口属性
long  __stdcall TCPSetInt(long Attrib, long  AValue);
long  __stdcall TCPSetObj(long Attrib, void* AValue);
long  __stdcall TCPSetStr(long Attrib, const char* AValue, long ASize);

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/* TCP 服务端的相关函数 */

// 创建/释放 TCP 服务端
void* __stdcall TCPServerCreate();
void  __stdcall TCPServerFree(void* ASrvObj);

// 打开/关闭 TCP 服务端
long  __stdcall TCPServerOpen(void* ASrvObj);
long  __stdcall TCPServerClose(void* ASrvObj);

// 取 TCP 服务端属性
// (返回值为属性值, ARetCode 为失败的返回码, 允许为空, 当字符串类型成功时为值尺寸)
long  __stdcall TCPServerGetInt(void* ASrvObj, long Attrib, long* ARetCode);
void* __stdcall TCPServerGetObj(void* ASrvObj, long Attrib, long* ARetCode);
char* __stdcall TCPServerGetStr(void* ASrvObj, long Attrib, long* ARetCode);

// 设置 TCP 服务端属性
long  __stdcall TCPServerSetInt(void* ASrvObj, long Attrib, long  AValue);
long  __stdcall TCPServerSetObj(void* ASrvObj, long Attrib, void* AValue);
long  __stdcall TCPServerSetStr(void* ASrvObj, long Attrib,
                          const char* AValue,  long ASize);

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/* TCP 客户端的相关函数 */

// 创建 TCP 客户端, 返回 RCKConnCreate 创建的对象
// 注:  TCP 客户端的释放调用 RCKConnFree 即可
//      TCP 客户端的属性是连接通讯槽对象的扩展属性项, kcaBaseSlotExt + Attrib
void* __stdcall TCPClientCreate();

}

#endif


 

--------------------------------------------------------------------------------

原文地址:https://www.cnblogs.com/riskyer/p/3318173.html