public void SetClientInfo(string clientID, int clientVer) { if (this.channel != null) { FTCAPI.FTAPIChannel_SetClientInfo(this.channel, clientID, clientVer); } }
public void SetRSAPrivateKey(string key) { if (this.channel != null) { FTCAPI.FTAPIChannel_SetRSAPrivateKey(this.channel, key); } }
public void Close() { if (this.channel != null) { FTCAPI.FTAPIChannel_Close(this.channel); } }
public ulong GetConnectID() { if (this.channel != null) { return(FTCAPI.FTAPIChannel_GetConnectID(this.channel)); } return(0); }
public void Close() { if (this.channel != null) { //FTCAPI.ReleaseFTAPIChannel(this.channel); FTCAPI.FTAPIChannel_Close(this.channel); } }
public bool InitConnect(string ip, ushort port, bool isEnableEncrypt) { if (this.channel != null) { int ret = FTCAPI.FTAPIChannel_InitConnect(this.channel, ip, port, isEnableEncrypt ? 1 : 0); return(ret == 0); } return(false); }
protected virtual void Dispose(bool disposing) { if (disposed) { return; } FTCAPI.ReleaseFTAPIChannel(channel); channel = (IntPtr)0; disposed = true; }
/// <summary> /// 清理底层库,程序退出时调用一次。 /// </summary> public static void UnInit() { lock (initLock) { if (!isInited) { return; } FTCAPI.FTAPIChannel_UnInit(); isInited = false; } }
/// <summary> /// 初始化底层库,程序启动时调用一次。 /// </summary> public static void Init() { lock (initLock) { if (isInited) { return; } FTCAPI.FTAPIChannel_Init(); isInited = true; } }
protected uint SendProto <TMessage, TBuilder>(uint protoID, GeneratedMessage <TMessage, TBuilder> req) where TMessage : Google.ProtocolBuffers.GeneratedMessage <TMessage, TBuilder> where TBuilder : Google.ProtocolBuffers.GeneratedBuilder <TMessage, TBuilder>, new() { if (this.channel != null) { byte[] data = req.ToByteArray(); IntPtr dataPtr = Marshal.AllocHGlobal(data.Length); Marshal.Copy(data, 0, dataPtr, data.Length); uint serialNo = FTCAPI.FTAPIChannel_SendProto(this.channel, protoID, (byte)0, dataPtr, data.Length); Marshal.FreeHGlobal(dataPtr); return(serialNo); } return(0); }
public FTAPI_Conn() { this.channel = FTCAPI.CreateFTAPIChannel(); FTCAPI.FTAPIChannel_SetProgrammingLanguage(this.channel, "C#"); this.initConnectCallback = (IntPtr pChannel, long errCode, string desc) => { this.OnInitConnect(errCode, desc); }; this.replyCallback = (IntPtr pChannel, int enReqReplyType, IntPtr protoHeaderPtr, IntPtr protoData, int nDataLen) => { ProtoHeader protoHeader = (ProtoHeader)Marshal.PtrToStructure(protoHeaderPtr, typeof(ProtoHeader)); byte[] data = null; if (nDataLen > 0 && protoData != IntPtr.Zero) { data = new byte[nDataLen]; Marshal.Copy(protoData, data, 0, nDataLen); } this.OnReply((ReqReplyType)enReqReplyType, protoHeader, data); }; this.pushCallback = (IntPtr pChannel, IntPtr protoHeaderPtr, IntPtr protoData, int nDataLen) => { ProtoHeader protoHeader = (ProtoHeader)Marshal.PtrToStructure(protoHeaderPtr, typeof(ProtoHeader)); byte[] data = new byte[nDataLen]; Marshal.Copy(protoData, data, 0, nDataLen); this.OnPush(protoHeader, data); }; this.disConnCallback = (IntPtr pChannel, long errCode) => { this.OnDisConnect(errCode); }; FTCAPI.FTAPIChannel_SetOnInitConnectCallback(channel, initConnectCallback); FTCAPI.FTAPIChannel_SetOnDisconnectCallback(channel, disConnCallback); FTCAPI.FTAPIChannel_SetOnReplyCallback(channel, replyCallback); FTCAPI.FTAPIChannel_SetOnPushCallback(channel, pushCallback); }