Commit 7fb42583 authored by 杨熙's avatar 杨熙

临时版本

parent 667e3393
......@@ -19,7 +19,7 @@ CPPFLAG += -DCCU_GIT_REVISION="\"$(CCU_GIT_INFO)\""
ALL=Konkexinghai
ALL=konkeyunzhiyi
SRCS=$(wildcard ../src/*.cpp)
SRCS+=$(wildcard ../src/lib/*.cpp)
SRCS+=$(wildcard ../src/lib/jsonlib/*.cpp)
......
......@@ -13,7 +13,7 @@ CCU_GIT_COMMIT_TIME = $(shell git log --date=iso --pretty=format:"%cd" $(CCU_GIT
CCU_GIT_INFO=$(CCU_GIT_REVISION) $(CCU_GIT_COMMIT_TIME)
CPPFLAG += -DCCU_GIT_REVISION="\"$(CCU_GIT_INFO)\""
ALL=Konkexinghai
ALL=konkeyunzhiyi
SRCS=$(wildcard ../src/*.cpp)
SRCS+=$(wildcard ../src/lib/*.cpp)
......
......@@ -14,7 +14,7 @@ CCU_GIT_INFO=$(CCU_GIT_REVISION) $(CCU_GIT_COMMIT_TIME)
CPPFLAG += -DCCU_GIT_REVISION="\"$(CCU_GIT_INFO)\""
ALL=Konkexinghai
ALL=konkeyunzhiyi
SRCS=$(wildcard ../src/*.cpp)
SRCS+=$(wildcard ../src/lib/*.cpp)
......
#include <stdio.h>
#include <string>
#include "json/writer.h"
#include "json/reader.h"
#include "json/value.h"
#include "KK_CcuConfig.h"
#include "LSC_Logger.h"
#include "KK_Util.h"
#include "MQ_CCU_Adapter.h"
KK_CcuConfig* KK_CcuConfig::ms_pInstance = NULL;
KK_CcuConfig* KK_CcuConfig::GetInstance() {
if (ms_pInstance == NULL) {
ms_pInstance = new KK_CcuConfig();
}
return ms_pInstance;
}
KK_CcuConfig::KK_CcuConfig(): db("hj", "hj", "127.0.0.1", "5432", "hjhome"){
}
int KK_CcuConfig::Open(){
try {
db.OpenConnection();
} catch (exception& e) {
LOGW("%s.\n",e.what());
return -1;
}
return 0;
}
//这个好像未用到
string KK_CcuConfig::getCentralAcGwMac(string NodeId){
string CentralAcGwMac = "";
DBRES result = NULL;
string sql = "SELECT mac from all_node_config where id = '"+NodeId+"';";
try {
db.StartTransaction();
result = db.ExecuteQuery(sql);
db.CommitTransaction();
if (result->size() == 1) {
CentralAcGwMac = result->at(0)->find("mac")->second;
} else {
LOGW("query table all_gw_config get error result size:%d.\n",result->size());
}
EH_DB::ReleaseResultSet(result);
} catch (exception& e) {
LOGW("%s.\n",e.what());
EH_DB::ReleaseResultSet(result);
}
return CentralAcGwMac;
}
This diff is collapsed.
/*
* KK_Update.h
*
* Created on: Dec 27, 2018
* Author: sds
*/
#ifndef KK_CCUCONFIG_H_
#define KK_CCUCONFIG_H_
#include <string>
#include "EH_DB.h"
using namespace std;
class KK_CcuConfig{
public: ////////先建立
class KKDevmapinfo {
public:
string dev_model_id;
string sn;
string mac;
};
public:
static KK_CcuConfig* GetInstance();
int Open();
string getCentralAcGwMac(string NodeId); //中控网关mac
private:
KK_CcuConfig();
private:
static KK_CcuConfig* ms_pInstance;
EH_DB db;
};
#endif /* KK_CCUCONFIG_H_ */
This diff is collapsed.
......@@ -22,6 +22,7 @@ using namespace std;
//#define DEV_CONFIG_FILE "/home/hj/hilink/config/hj_hwdev.json"
//#define PROFILE_CONFIG_FILE "/home/hj/hilink/config/hj_hwprofile.json"
#define ROOM_ID_FILE "/home/hj/Roma/config/hj_hwroomid.json"
//#define ScenePaneName_FILE "/home/hj/hilink/config/hj_hwscenname.json"
#define CONNECT_STATE_FILE "/home/hj/Roma/config/hj_hwconnectstate.json"
#if defined(NOT_X86)
......
......@@ -27,9 +27,11 @@
#include "EH_Exception.h"
#include "KK_CcuConfig.h"
#define CCU_REQ_TIMEOUT 3
//单例模式
//下面这部分代码是什么意思?
MQ_CCU_Adapter* MQ_CCU_Adapter::ms_pInstance = NULL;
MQ_CCU_Adapter* MQ_CCU_Adapter::GetInstance() {
......@@ -144,6 +146,9 @@ int MQ_CCU_Adapter::open() {
client = new EH_Client();
client->init("", "", this, false);
//开启TCP 与UDP
kk_connect::GetInstance()->init( KK_HwDevManager::GetInstance()->getCcuId(), "",false);
//连接Roma平台,绑定就进行启动
oninitmqttsdk();
return 0;
......@@ -321,7 +326,7 @@ int MQ_CCU_Adapter::send_Control_Info(string wholeMsg){
int MQ_CCU_Adapter::addCCuroom(){
EH::Json::Value roomarg;
roomarg["name"] = "xlink特定房间不可删";
roomarg["name"] = "Roma特定房间不可删";
roomarg["room_icon"] = "a_0";
roomarg["floor_id"] = "3";
roomarg["room_pos"] = "10";
......@@ -335,7 +340,7 @@ int MQ_CCU_Adapter::saveCCuroom(EH::Json::Value arg){
if(SaveRoomEnable){
KK_HwDevManager::KKRoomId roominfo;
roominfo.roonid = ccuroomid;
roominfo.name = "xlink特定房间不可删";
roominfo.name = "Roma特定房间不可删";
onlyroomid[ccuroomid] = roominfo;
LOGD("prepare add room \n");
KK_HwDevManager::GetInstance()->saveroomid(onlyroomid);
......@@ -941,23 +946,21 @@ void MQ_CCU_Adapter::oninitmqttsdk() {
try {
//goto跳转,谨慎使用。
loop:
// EH::Json::Value connectStateInfo = KK_HwDevManager::GetInstance()->loadConnectState();//获取绑定信息
// if(connectStateInfo["result"] == "1"){
// string heartbeat_Topic;
// clientId = connectStateInfo["client_id"].asString();
// username = connectStateInfo["device_name"].asString();
ccuId = MQ_CCU_Config::GetInstance()->getCcuId(); //获取主机ID
EH::Json::Value connectStateInfo = KK_HwDevManager::GetInstance()->loadConnectState();//获取绑定信息
if(connectStateInfo["result"] == "1"){
string heartbeat_Topic;
clientId = connectStateInfo["client_id"].asString();
username = connectStateInfo["device_name"].asString();
//订阅的 Topic
ptpoTopic = string("$xlink/ptpo/{")+ccuId+"}"; //ptpo运维
ptpTopic = string("$xlink/ptp/{")+ccuId+"}"; //ptp交互
heartbeat_Topic = string("$xlink/ptp/{")+ccuId+"}/ptp_keepalive"; //心跳
LOGD("pushTopic is: %s subTopic is: %s \n",pushTopic.c_str(),subTopic.c_str());
int ret = mqttSdk->init(MQ_CCU_Config::GetInstance()->getBrokerAddr(), //正式环境
"KONKE-KK-QWER1234QWER1234","","",heartbeat_Topic,gw_id);
// int ret = mqttSdk->init(MQ_CCU_Config::GetInstance()->getBrokerAddr(), //正式环境
// clientId,"2CEDC38940644E439649389C08329B09","}A12a#RM^r)iXy/?|sHW:z3!",willTopic,heartbeat_Topic,gw_id);
pushTopic = string("xChfVJ501599/out/")+username;
subTopic = string("xChfVJ501599/in/")+username; //****************临时信息
willTopic = string("xChfVJ501599/out/")+username+"/heartbeat"; //遗嘱信息
heartbeat_Topic = string("xChfVJ501599/out/")+username+"/heartbeat";
LOGD("pushTopic is: %s subTopic is: %s willTopic is: %s\n",pushTopic.c_str(),subTopic.c_str(),willTopic.c_str());
int ret = mqttSdk->init("127.0.0.1:23883", //正式环境
clientId,"2CEDC38940644E439649389C08329B09","}A12a#RM^r)iXy/?|sHW:z3!",willTopic,heartbeat_Topic,gw_id);
mqttOnline = false;
if(ret == 0){
mqttSdk->con(1,3);
......
This diff is collapsed.
......@@ -135,9 +135,9 @@ private:
string clientId;
string username;
string ptpoTopic ;
string ptpTopic;
// string willTopic;
string pushTopic ;
string subTopic;
string willTopic;
bool KKdiscover;
bool ccuSyncOK;
......
......@@ -24,6 +24,7 @@ MQ_CCU_Config* MQ_CCU_Config::GetInstance() {
}
MQ_CCU_Config::MQ_CCU_Config() {
logLevel = "D";
}
......
This diff is collapsed.
......@@ -35,21 +35,21 @@ int ACE_TMAIN(int argc, ACE_TCHAR* argv[]) { //主函数
EH_ToolKit::SetCoredumpMsgDump();
//开启日志并开始记录
if (LSC_LOGGER::instance()->open("konkeyunzhiyi", DEF_LOG_LEAVE) != 0) {
if (LSC_LOGGER::instance()->open("Konkexinghai", DEF_LOG_LEAVE) != 0) {
LOGE("Init lsc logger failed.\n");
ACE_OS::exit(1);
}
//创建ACE_进程 konkeyunzhiyi
ACE_Process_Mutex processMutex("konkeyunzhiyi"); //进程名检测
//创建ACE_进程 Konkexinghai
ACE_Process_Mutex processMutex("Konkexinghai"); //进程名检测
if (processMutex.tryacquire() < 0) { //
//相同的进程正在运行,当前进程将中止 。异常的判段处理
LOGE("The same process is running.current process will abort.\n");
return -1;
} else {
LOGI("konke yunzhiyi Starting...Version:%s \n",MQ_VERSION);
LOGI("konke yunzhiyi Starting...Version 编译时间:%s %s \n",__DATE__,__TIME__);
LOGI("konke yunzhiyi acquired.\n");
LOGI("Konke xinghai Starting...Version:%s \n",MQ_VERSION);
LOGI("Konke xinghai Starting...Version 编译时间:%s %s \n",__DATE__,__TIME__);
LOGI("Konkexinghai acquired.\n");
}
if(KK_CcuConfig::GetInstance()->Open()!=0){
......@@ -87,11 +87,9 @@ static int serverSocket;
static void processReq(string req) { //处理请求
if(req == "new_mqtt_tcp"){
// KK_MQTTSDK::GetInstance()->reinit("tcp://121.37.12.6:1883");
KK_MQTTSDK::GetInstance()->reinit("tcp://127.0.0.1:23883");
KK_MQTTSDK::GetInstance()->reinit("tcp://121.37.12.6:1883");
}else if(req == "new_mqtt_ssl"){
// KK_MQTTSDK::GetInstance()->reinit("ssl://120.55.149.201:8883");
KK_MQTTSDK::GetInstance()->reinit("ssl://127.0.0.1:23883");
KK_MQTTSDK::GetInstance()->reinit("ssl://120.55.149.201:8883");
}else if(req == "con_mqtt_0") {
KK_MQTTSDK::GetInstance()->con(0);
}else if(req == "con_mqtt_1") {
......
This diff is collapsed.
/*
* EH_DB.h
* Copyright by AirDream Co., Ltd. 2010-2011 All right reserved
*
* Description:
* Created on:2011-12-22
* Modified on:2011-12-22
*
*/
//#define NOT_X86
#ifndef NOT_X86
#ifndef EH_DB_H_
#define EH_DB_H_
#include <iostream>
#include <string>
#include <pqxx/pqxx>
#include "ace/Recursive_Thread_Mutex.h"
using namespace std;
using namespace pqxx;
typedef vector<map<string, string>*> DBRESVEC;
typedef vector<map<string, string>*>* DBRES;
typedef map<string, string> DBROWMAP;
typedef map<string, string>* DBROW;
class EH_DB {
public:
EH_DB(string username,string passwd,string addr,string port,string dbname);
~EH_DB();
void OpenConnection();
void CloseConnection();
void ResetConnection();
void StartTransaction();
void CommitTransaction();
void AbortTransaction();
void ExceptionInTransaction();
DBRES ExecuteQuery(string sql);
int ExecuteUpdate(string sql);
static void ReleaseResultSet(DBRES& res);
private:
connection* m_pConn;
transaction<>* m_pAction;
string m_strConnectionInfo;
ACE_Recursive_Thread_Mutex m_Lock;
};
#endif /* EH_DB_H_ */
#else
#include "EH_DB_Sqlite.h"
#endif
/*
* EH_DB.h
*
* Created on: 2013-9-10
* Author: sj
usage:
try {
StartTransaction();
ExecuteQuery
ExecuteUpdate
.....
CommitTransaction();
} catch (...) {
ExceptionInTransaction();//NOTE!!
....//custom process code
}
modify by zgm at 2016-5-6
*/
#ifdef NOT_X86
#ifndef EH_DB_H_
#define EH_DB_H_
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include "ace/Recursive_Thread_Mutex.h"
#include "ace/Process_Mutex.h"
#include "EH_Sqlite3.h"
using namespace std;
typedef vector<map<string, string>*> DBRESVEC;
typedef vector<map<string, string>*>* DBRES;
typedef map<string, string> DBROWMAP;
typedef map<string, string>* DBROW;
class EH_DB {
public:
EH_DB(string username,string passwd,string addr,string port,string dbname);
~EH_DB();
/*
* If already have a connection,don't get a new connection.
* if success return 0, else are other values.
*/
int OpenConnection();
/*
* close the db connection
*/
void CloseConnection();
/*
* if success return 0, else are other values.
*/
int ResetConnection();
/*
* if success return 0, else are other values.
*/
int StartTransaction();
/*
* if success return 0, else are other values.
*/
int CommitTransaction();
/*
* if success return 0, else are other values.
*/
int AbortTransaction();
/* must be called when exception occur when in executing a transaction.
* if success return 0, else are other values.
*/
int ExceptionInTransaction();
/*
* release the DBRES is the application's responsibility
*/
DBRES ExecuteQuery(string sql);
void ExecuteUpdate(string sql);
static void ReleaseResultSet(DBRES& res);
private:
private:
void* m_pConn;
string m_strConnectionInfo;
int m_iTransactionFlag;
int m_iErrCode;
};
#endif /* EH_DB_H_ */
#endif
......@@ -29,7 +29,7 @@ public:
public:
static KK_MQTTSDK* GetInstance();
int init(string brokerAddr,string clientId,string username,string password,string heartbeat_Topic,string gw_id);
int init(string brokerAddr,string clientId,string username,string password,string willTopic,string heartbeat_Topic,string gw_id);
int subTopic(string topic,int qos = 0,int waitTimeout = 0);
int unsubTopic(string topic,int waitTimeout = 0);
......
/*
* kk_connect.cpp
*
* Created on: 2020年10月1日
* Author: hj
*/
#include <arpa/inet.h>
#include <errno.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#include <iostream>
#include <sys/socket.h>
#include <netinet/in.h>
#include "json/reader.h"
#include "json/writer.h"
#include "json/value.h"
#include "EH_ToolKit.h"
#include "EH_FindCCU.h"
#include "kk_connect.h"
#include "LSC_Logger.h"
#include "MQ_CCU_Adapter.h"
kk_connect* kk_connect::ms_instance = NULL;
kk_connect* kk_connect::GetInstance() {
if (ms_instance == NULL) {
ms_instance = new kk_connect();
}
return ms_instance;
}
kk_connect::kk_connect() {
}
void* kk_connect::run0(void* opt) {
kk_connect* client = (kk_connect*) opt;
return client->run(opt);
}
//
int kk_connect::init(string ccuId, string accessKey, bool autoDestroyHandler) {
this->ccuId = ccuId;
this->accessKey = accessKey;
this->ccuServerPort = SERVER_LISTEN_PORT;
this->autoDestroyHandler = autoDestroyHandler;
#ifdef NOT_X86
this->ccuLocalIP = string(EH_ToolKit::GetLocalIP("eth1"));
#else
this->ccuLocalIP = string(EH_ToolKit::GetLocalIP());
#endif
this->ccuSn = EH_ToolKit::GetMacNoSpace();
LOGI(" ccuLocalIP:%s.\n", ccuLocalIP.c_str());
ccuServerIp = ccuLocalIP;
ccuServerPort = 6768;
findCCU = new EH_FindCCU();
// findCCU->init(ccuId, this,ccuLocalIP);
findCCU->init(ccuId,ccuLocalIP);
pthread_t tid;
pthread_create(&tid, NULL, run0, this);
return 0;
}
string kk_connect::sendLoginReq(string msg) {
string loginReq = "";
string logingwsn = ccuSn;
EH::Json::Reader reader;
EH::Json::Value buf;
if (!reader.parse(msg, buf) || !buf.isObject()) {
LOGW("Message format is wrong. msg is: %s\n",msg.c_str());
return "-1";
}
try{
EH::Json::Value arg;
arg["method"] = "bind";
arg["gw_id"] = buf["gw_id"];
arg["client_id"] = buf["client_id"];
arg["device_name"] = buf["device_name"];
//错误类型
//网关ID不符result=3 ;
if(logingwsn != buf["gw_id"].asString()){
// arg["gw_id"] = logingwsn;
arg["result"] = "3";
loginReq = arg.toStyledString();
return loginReq;
}
//网关未联网result=2
//进行网络校验
if (EH_ToolKit::Ping(string("114.114.114.114"))!= true) {
arg["result"] = "2";
loginReq = arg.toStyledString();
return loginReq;
}
//网关已被绑定result=1(如需绑定,请先解除绑定)
EH::Json::Value connectStateInfo = KK_HwDevManager::GetInstance()->loadConnectState();//获取绑定信息
if(connectStateInfo["result"] == "0"){ //0为未绑定
EH::Json::Value newconnectInfo;
newconnectInfo["result"] = "1";
newconnectInfo["client_id"] = buf["client_id"];
newconnectInfo["device_name"] = buf["device_name"];
int saveok = KK_HwDevManager::GetInstance()->saveConnectState(newconnectInfo);//获取绑定信息
LOGI("saves :%d.\n",saveok);
//保存成功就会进行连接Roma程序启动。void MQ_CCU_Adapter::oninitmqttsdk()
arg["result"] = "0"; //绑定成功result=0,
loginReq = arg.toStyledString();
return loginReq;
}else{
arg["result"] = "1"; //网关已被绑定result=1
loginReq = arg.toStyledString();
return loginReq;
}
} catch (exception &e) {
LOGW("%s.\n", e.what());
}
return "-1";
}
//
void* kk_connect::run(void* opt) {
//定义用于连接,和接收的socket
// bind
try{
int socket_fd,accept_fd;
sockaddr_in myserver, remote_addr;
if(( socket_fd = socket(PF_INET,SOCK_STREAM,IPPROTO_TCP)) < 0 ){
LOGW("socket() failed!.\n");
}
memset(&myserver,0,sizeof(myserver));
myserver.sin_family = AF_INET;
myserver.sin_addr.s_addr = htonl(INADDR_ANY);
myserver.sin_port = htons(6768);
//使用端口复用,在bind之前先设置好socket的选线,让其可以绑定在已经正在被别的socket使用的端口上。
setsockopt(socket_fd,SOL_SOCKET,SO_REUSEADDR,(const void*)&opt,sizeof(1));
if( bind(socket_fd,(sockaddr*) &myserver,sizeof(myserver)) < 0 ) {
LOGW("bind() failed!.\n");
}
// listen
if( listen(socket_fd,50) < 0 ) {
LOGW("listen() failed!.\n");
}
LOGI("Step3: 侦听.\n");
// while(!destroyed) {
while(true) {
socklen_t sin_size = sizeof(struct sockaddr_in);
if(( accept_fd = accept(socket_fd,(struct sockaddr*) &remote_addr,&sin_size)) == -1 ){
LOGI("收发数据%d.\n",accept_fd);
LOGW("Accept error!.\n");
continue;
}
LOGI("收发数据%d.\n",accept_fd);
LOGI("Received a connection from %s\n",(char*) inet_ntoa(remote_addr.sin_addr));
if(!fork() ) {
char buffer[RECV_MSG_SIZE];
memset(buffer,0,RECV_MSG_SIZE);
if((read(accept_fd,buffer,RECV_MSG_SIZE)) < 0) {
LOGW("Accept error!.\n");
throw("Read() error!");
} else {
LOGI("收到的消息: %s\n",buffer);
string sendbuffer = buffer;
string loginReq = sendLoginReq(sendbuffer);
int loginReq_Len = loginReq.length();
//对下面进行封装,达到发送信息的要求
if(loginReq != "-1"){
LOGI("发送的消息: %s\n",loginReq.c_str());
send(accept_fd, (void *)loginReq.c_str(), loginReq_Len, 0);
}
}
}
close(accept_fd);
// close(socket_fd);
}
delete this;
} catch (exception &e) {
LOGW("%s.\n", e.what());
}
return NULL;
}
void kk_connect::destroy() {
// destroyed = true;
// close(connectToCcuFd);
LOGI("destroy:%s.\n", ccuId.c_str());
}
kk_connect::~kk_connect() {
// close(connectToCcuFd);
if (findCCU) {
findCCU->destroy();
findCCU = NULL;
}
LOGI("~EH_Client:%p.\n", this);
}
This diff is collapsed.
/*
* kk_connect.h
*
* Created on: 2020年10月1日
* Author: hj
*/
#ifndef KK_CONNECT_H_
#define KK_CONNECT_H_
#include <sys/types.h>
#include <vector>
#include <string>
#include "json/value.h"
// #include "../KK_HwDevManager.h"
using namespace std;
class EH_FindCCU;
class kk_connect{
public:
static kk_connect* GetInstance();
kk_connect();
virtual ~kk_connect();
int init(string ccuId, string accessKey,bool autoDestroyHandler);
static void* run0(void* opt);
void destroy();
private:
static kk_connect* ms_instance;
void* run(void* opt);
string sendLoginReq(string msg);
private:
string ccuId;
string accessKey;
string ccuServerIp;
string ccuLocalIP;
u_short ccuServerPort;
string ccuSn;
bool autoDestroyHandler;
EH_FindCCU* findCCU;
// string cacheInputMsg;
};
#endif /* KK_CONNECT_H_ */
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/*
* EH_DB.cpp
* Copyright by AirDream Co., Ltd. 2010-2011 All right reserved
*
* Description:
* Created on:2011-12-22
* Modified on:2011-12-22
*
*/
#ifndef NOT_X86
#include "EH_DB.h"
#include "EH_DEBUG.h"
EH_DB::EH_DB(string username, string passwd,
string addr, string port,string dbname) {
string conn = "";
conn.append("dbname=");
conn.append(dbname);
conn.append(" ");
conn.append("host=");
conn.append(addr);
conn.append(" ");
conn.append("port=");
conn.append(port);
conn.append(" ");
conn.append("user=");
conn.append(username);
conn.append(" ");
conn.append("password=");
conn.append(passwd);
m_strConnectionInfo = conn;
m_pConn = NULL;
m_pAction = NULL;
}
/*
*If already have a connection,don't get a
*new connection.
*/
void EH_DB::OpenConnection() {
m_Lock.acquire();
if (m_pConn == NULL) {
m_pConn = new connection(m_strConnectionInfo);
}
m_Lock.release();
}
void EH_DB::ResetConnection() {
m_Lock.acquire();
CloseConnection();
OpenConnection();
m_Lock.release();
}
void EH_DB::CloseConnection() {
m_Lock.acquire();
if (m_pConn) {
m_pConn->disconnect();
delete m_pConn;
m_pConn = NULL;
}
m_Lock.release();
}
void EH_DB::StartTransaction() {
m_Lock.acquire();
if (m_pAction) {
delete m_pAction;
m_pAction = NULL;
}
m_pAction = new transaction<>(*m_pConn, "EH_DB");
}
void EH_DB::CommitTransaction() {
if (m_pAction) {
m_pAction->commit();
delete m_pAction;
m_pAction = NULL;
m_Lock.release();
}
}
void EH_DB::AbortTransaction() {
if (m_pAction) {
m_pAction->abort();
delete m_pAction;
m_pAction = NULL;
m_Lock.release();
}
}
/*must be called when exception occur when in executing a transaction.
usage:
try {
StartTransaction();
ExecuteQuery
ExecuteUpdate
.....
CommitTransaction();
} catch (...) {
ExceptionInTransaction();//NOTE!!
....//custom process code
}
*/
void EH_DB::ExceptionInTransaction() {
if (m_pAction) {
delete m_pAction;
m_pAction = NULL;
}
m_Lock.release();
}
DBRES EH_DB::ExecuteQuery(string sql) {
if (m_pConn == NULL) {
throw runtime_error("EXCEPTION:connection instance is NULL");
}
if (m_pAction == NULL) {
throw runtime_error("EXCEPTION:transaction instance is NULL");
}
result R = m_pAction->exec(sql);
DBRES result = new DBRESVEC();
DBROW row = NULL;
for (uint i = 0; i < R.size(); i++) {
row = new DBROWMAP();
for (uint j = 0; j < R.columns(); j++) {
string colName = R.column_name(j);
string vlaue(R[i][colName].c_str());
row->insert(DBROWMAP::value_type(colName, vlaue));
}
result->push_back(DBRESVEC::value_type(row));
row = NULL;
}
return result;
}
int EH_DB::ExecuteUpdate(string sql) {
if (m_pConn == NULL) {
throw runtime_error("EXCEPTION:connection instance is NULL");
}
if (m_pAction == NULL) {
throw runtime_error("EXCEPTION:transaction instance is NULL");
}
result ret = m_pAction->exec(sql);
return ret.affected_rows();
}
void EH_DB::ReleaseResultSet(DBRES& res) {
if (!res) {
return;
}
DBRESVEC::const_iterator it = res->begin();
while (it != res->end()) {
DBROW row = *it;
if (row) {
delete row;
row = NULL;
}
++it;
}
delete res;
res = NULL;
}
EH_DB::~EH_DB() {
CloseConnection();
}
#endif
This diff is collapsed.
This diff is collapsed.
EH_DB_Sqlite.o: ../src/lib/EH_DB_Sqlite.cpp
EH_Exception.o: ../src/lib/EH_Exception.cpp ../src/include/EH_Exception.h
This diff is collapsed.
EH_GetCallStack.o: ../src/lib/EH_GetCallStack.cpp ../src/lib/EH_DEBUG.h
This diff is collapsed.
This diff is collapsed.
......@@ -149,7 +149,7 @@ void KK_MQTTSDK::recon(int delayInSec){
}
}
int KK_MQTTSDK::init(string brokerAddr,string clientId,string username,string password,string heartbeat_Topic,string gw_id) {
int KK_MQTTSDK::init(string brokerAddr,string clientId,string username,string password,string willTopic,string heartbeat_Topic,string gw_id) {
LOGD("MQTT 初始化.\n");
if(this->callbackHandler == NULL){
LOGE("callbackHandler not set.\n");
......@@ -159,7 +159,7 @@ int KK_MQTTSDK::init(string brokerAddr,string clientId,string username,string pa
this->clientId = clientId;
this->username = username;
this->password = password;
// this->willTopic = willTopic;
this->willTopic = willTopic;
this->heartbeat_Topic = heartbeat_Topic;
this->gw_id = gw_id;
......@@ -401,8 +401,8 @@ void* KK_MQTTSDK::run(void* opt){
//与Roma平台30秒心跳
sleep(30);
LOGD("Topic:%s Payload:%s\n",heartbeat_Topic.c_str(),sendPayload.c_str());
sendMsg(heartbeat_Topic,sendPayload,0);
// LOGD("Topic:%s Payload:%s\n",heartbeat_Topic.c_str(),sendPayload.c_str());
// sendMsg(heartbeat_Topic,sendPayload,0);
}
//delete this;
return NULL;
......
This diff is collapsed.
KK_Util.o: ../src/lib/KK_Util.cpp ../src/include/KK_Util.h
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment