Find file
f51bbbb Dec 27, 2016
134 lines (97 sloc) 4.74 KB
// Tencent is pleased to support the open source community by making GAutomator available.
// Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
// Licensed under the MIT License (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
// Unless required by applicable law or agreed to in writing, software distributed under the License is
// either express or implied. See the License for the specific language governing permissions and
// limitations under the License.
// stn_logic.h
// network
// Created by yanguoyue on 16/2/18.
// Copyright © 2016年 Tencent. All rights reserved.
#include <stdint.h>
#include <string>
#include <map>
#include <vector>
#include "mars/comm/autobuffer.h"
#include "mars/stn/stn.h"
namespace mars{
namespace stn{
//callback interface
class Callback
virtual ~Callback() {}
virtual bool MakesureAuthed() = 0;
virtual void TrafficData(ssize_t _send, ssize_t _recv);
virtual std::vector<std::string> OnNewDns(const std::string& host);
virtual void OnPush(int32_t cmdid, const AutoBuffer& msgpayload) = 0;
virtual bool Req2Buf(int32_t taskid, void* const user_context, AutoBuffer& outbuffer, int& error_code, const int channel_select) = 0;
virtual int Buf2Resp(int32_t taskid, void* const user_context, const AutoBuffer& inbuffer, int& error_code, const int channel_select) = 0;
virtual int OnTaskEnd(int32_t taskid, void* const user_context, int error_type, int error_code) = 0;
virtual void ReportFlow(int32_t wifi_recv, int32_t wifi_send, int32_t mobile_recv, int32_t mobile_send) = 0;
virtual void ReportConnectStatus(int status, int longlink_status) = 0;
virtual int GetLonglinkIdentifyCheckBuffer(AutoBuffer& identify_buffer, AutoBuffer& buffer_hash, int32_t& cmdid) = 0;
virtual bool OnLonglinkIdentifyResponse(const AutoBuffer& response_buffer, const AutoBuffer& identify_buffer_hash) = 0;
virtual void RequestSync() = 0;
virtual bool IsLogoned() = 0;
void SetCallback(Callback* const callback);
void SetLonglinkSvrAddr(const std::string& host, const std::vector<uint16_t> ports);
void SetShortlinkSvrAddr(const uint16_t port);
// 'host' will be ignored when 'debugip' is not empty.
void SetLonglinkSvrAddr(const std::string& host, const std::vector<uint16_t> ports, const std::string& debugip);
// '' will be ignored when 'debugip' is not empty.
void SetShortlinkSvrAddr(const uint16_t port, const std::string& debugip);
// setting debug ip address for the corresponding host
void SetDebugIP(const std::string& host, const std::string& ip);
// setting backup iplist for the corresponding host
// if debugip is not empty, iplist will be ignored.
// iplist will be used when newdns/dns ip is not available.
void SetBackupIPs(const std::string& host, const std::vector<std::string>& iplist);
// async function.
void StartTask(const Task& task);
// sync function
void StopTask(int32_t taskid);
// check whether task's list has the task or not.
bool HasTask(int32_t taskid);
// reconnect longlink and redo all task
// when you change svr ip, you must call this function.
void RedoTasks();
// stop and clear all task
void ClearTasks();
// the same as ClearTasks(), but also reinitialize network.
void Reset();
//setting signalling's parameters.
//if you did not call this function, stn will use default value: period: 5s, keeptime: 20s
void SetSignallingStrategy(long period, long keeptime);
// used to keep longlink active
// keep signnaling once 'period' and last 'keeptime'
void KeepSignalling();
void StopSignalling();
// connect quickly if longlink is not connected.
void MakesureLonglinkConnected();
bool LongLinkIsConnected();
// noop is used to keep longlink conected
// get noop taskid
uint32_t getNoopTaskID();
#endif /* MARS_STN_LOGIC_H_ */