增加物联客户端,编译未通过

This commit is contained in:
大石头 2017-08-15 00:42:29 +08:00
parent 3264ce1596
commit 292646b129
5 changed files with 1419 additions and 0 deletions

1300
Link/LinkClient.cpp Normal file

File diff suppressed because it is too large Load Diff

111
Link/LinkClient.h Normal file
View File

@ -0,0 +1,111 @@
#ifndef __LinkClient_H__
#define __LinkClient_H__
#include "Kernel\Sys.h"
#include "Message\DataStore.h"
#include "Message\Json.h"
// 物联客户端
class LinkClient
{
public:
bool Opened;
int Status; // 状态。0准备、1握手完成、2登录后
UInt64 LoginTime; // 登录时间ms
UInt64 LastSend; // 最后发送时间ms
UInt64 LastActive; // 最后活跃时间ms
int Delay; // 心跳延迟。一条心跳指令从发出到收到所花费的时间
int MaxNotActive; // 最大不活跃时间ms超过该时间时重启系统。默认0
DataStore Store; // 数据存储区
Dictionary<cstring, IDelegate*> Routes; // 路由集合
LinkClient();
void Open();
void Close();
// 发送消息
bool Send(TokenMessage& msg, TokenController* ctrl = nullptr);
bool Reply(TokenMessage& msg, TokenController* ctrl = nullptr);
void OnReceive(TokenMessage& msg, TokenController& ctrl);
void OnReceiveLocal(TokenMessage& msg, TokenController& ctrl);
void LocalSend(int start, const Buffer& bs);
// 收到功能消息时触发
MessageHandler Received;
void* Param;
// 常用系统级消息
// 握手广播
void SayHello(bool broadcast);
// 注册
void Register();
// 登录
void Login();
// 重置并上报
void Reset(const String& reason);
void Reboot(const String& reason);
// Ping指令用于保持与对方的活动状态
void Ping();
void Read(int start, int size);
void Write(int start, const Buffer& bs);
void Write(int start, byte dat);
// 异步上传并等待响应,返回实际上传字节数
int WriteAsync(int start, const Buffer& bs, int msTimeout);
// 必须满足 start > 0 才可以。
void ReportAsync(int start, uint length = 1);
// 远程调用
void Invoke(const String& action, const Buffer& bs);
// 远程调用委托。传入参数名值对以及结果缓冲区引用业务失败时返回false并把错误信息放在结果缓冲区
typedef bool(*InvokeHandler)(void* param, const Pair& args, Stream& result);
// 注册远程调用处理器
void Register(cstring action, InvokeHandler handler, void* param = nullptr);
// 模版支持成员函数
template<typename T>
void Register(cstring action, bool(T::*func)(const Pair&, Stream&), T* target)
{
Register(action, *(InvokeHandler*)&func, target);
}
static LinkClient* Current;
private:
// 跳转
bool OnRedirect(HelloMessage& msg);
bool OnLogin(TokenMessage& msg, TokenController* ctrl);
bool OnPing(TokenMessage& msg, TokenController* ctrl);
bool ChangeIPEndPoint(const NetUri& uri);
void OnRead(const TokenMessage& msg, TokenController* ctrl);
void OnWrite(const TokenMessage& msg, TokenController* ctrl);
void OnInvoke(const TokenMessage& msg, TokenController* ctrl);
bool OnInvoke(const String& action, const Pair& args, Stream& result);
private:
uint _task;
void* _Expect; // 等待内容
int NextReport = -1; // 下次上报偏移,-1不动
byte ReportLength; // 下次上报数据长度
void LoopTask();
bool CheckReport();
void CheckNet();
};
#endif

View File

@ -17,6 +17,7 @@ build.AddFiles("..\\Test");
build.AddFiles("..\\TinyIP", "*.c;*.cpp", false, "HttpClient"); build.AddFiles("..\\TinyIP", "*.c;*.cpp", false, "HttpClient");
build.AddFiles("..\\TinyNet"); build.AddFiles("..\\TinyNet");
build.AddFiles("..\\TokenNet"); build.AddFiles("..\\TokenNet");
build.AddFiles("..\\Link");
build.AlwaysBuild = "Sys.cpp"; build.AlwaysBuild = "Sys.cpp";
build.Libs.Clear(); build.Libs.Clear();
//build.Preprocess = true; //build.Preprocess = true;

View File

@ -106,6 +106,7 @@
<ClCompile Include="..\Kernel\Thread.cpp" /> <ClCompile Include="..\Kernel\Thread.cpp" />
<ClCompile Include="..\Kernel\Time.cpp" /> <ClCompile Include="..\Kernel\Time.cpp" />
<ClCompile Include="..\Kernel\WaitHandle.cpp" /> <ClCompile Include="..\Kernel\WaitHandle.cpp" />
<ClCompile Include="..\Link\LinkClient.cpp" />
<ClCompile Include="..\Message\BinaryPair.cpp" /> <ClCompile Include="..\Message\BinaryPair.cpp" />
<ClCompile Include="..\Message\Controller.cpp" /> <ClCompile Include="..\Message\Controller.cpp" />
<ClCompile Include="..\Message\DataStore.cpp" /> <ClCompile Include="..\Message\DataStore.cpp" />

View File

@ -49,6 +49,9 @@
<Filter Include="Drivers\Esp8266"> <Filter Include="Drivers\Esp8266">
<UniqueIdentifier>{5148c153-2531-43dd-b3d0-c6e56c956568}</UniqueIdentifier> <UniqueIdentifier>{5148c153-2531-43dd-b3d0-c6e56c956568}</UniqueIdentifier>
</Filter> </Filter>
<Filter Include="Link">
<UniqueIdentifier>{f7ce12fa-0f45-4e6e-bc63-a16c0fd2ca7e}</UniqueIdentifier>
</Filter>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\Core\Type.cpp"> <ClCompile Include="..\Core\Type.cpp">
@ -581,5 +584,8 @@
<ClCompile Include="..\Message\HistoryStore.cpp"> <ClCompile Include="..\Message\HistoryStore.cpp">
<Filter>Message</Filter> <Filter>Message</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\Link\LinkClient.cpp">
<Filter>Link</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
</Project> </Project>