派生自 development/c++

pansen
2019-03-07 979bc003bce710bf300bc2bd87a8278585678763
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include <stdio.h>
#include <iostream>
#include <unistd.h>
#include <cstring>
#include "RtspAnalysManager.h"
#include <basic/debug/Debug.h>
#include <thread>
#include <Ice/Ice.h>
#include <basic/rpc/IceRpc.hpp>
//"192.168.1.4", 8000, "admin", "basic123"
 
using namespace std;
 
#include <basic/util/file/FileUtil.h>
#include <basic/util/app/AppPreference.hpp>
#include <basic/util/app/AppConfig.h>
 
#include <GB28181Server.h>
#include <basic/util/net_config/net_config.h>
#include <DataManagerServer/vss/dao/VssLocalSettingTblSqliteDao.h>
 
static void startManager(LDBTool *_dbTool) {
    RtspAnalysManager rtspAnalysManager(_dbTool);
    while (1) {
        sleep(1 * 60 * 60 * 12);
    }
}
 
std::string getLocalIp() {
    unsigned char netmask_old[15] = {0};
    unsigned char gateway_old[15] = {0};
    unsigned char ip_old[15] = {0};
 
    std::string net_ifname = appConfig.getStringProperty("netIfName");
    std::string str_ip;
 
    if (GetIpAddress(net_ifname.c_str(), ip_old)) {
        std::string ip_old_temp((char *) ip_old);
        str_ip = ip_old_temp;
    } else {
//        value["ipaddr"] = "";
        ERR("not get ip addr");
    }
    assert(!str_ip.empty());
    return std::move(str_ip);
}
 
/***
 * arg1 为-1时启用gb28181
 * @param argc
 * @param argv
 * @return
 */
int main(int argc, char **argv) {
    std::cout << __DATE__ << " " << __TIME__ << std::endl;
    SAVE_APP_ARGS
 
#ifdef GLOG
    ENABLEGLOG(GET_STR_CONFIG("logPath").c_str());
#endif
 
    if (argc < 4) {
        assert("t_value.size()");
    }
    {
//            std::string rtmpAddr = appConfig.getStringProperty("srsAddr");
//            std::string publish_basepath = rtmpAddr + "" ;
//            appPref.setStringData("publish.basepath", publish_basepath);
        appPref.setIntData("pulish.width", 640);
        appPref.setIntData("pulish.height", 360);
    }
    int arg1 = atoi(argv[1]);
 
    int gindx = abs(arg1) % 2;
    int GB28181_Enable = arg1 < 0 ? 1 : 0;
 
    DBG(gindx);
    appPref.setIntData("GB28181_Enable", GB28181_Enable);
    appPref.setLongData("gpu.index", gindx);
    appPref.setIntData("show.image", 0);
 
    //todo
    appPref.setIntData("CamStart", arg1);
    appPref.setIntData("CamStep", atoi(argv[2]));
    appPref.setIntData("RpcServerPort", atoi(argv[3]));
    if (GB28181_Enable) {
        //#todo search from db
        MysqlDBServerCfg mysqlDBServerCfg;
        mysqlDBServerCfg.Host = getLocalIp();
        mysqlDBServerCfg.Port = 3306;
        mysqlDBServerCfg.UserName = "root";
        mysqlDBServerCfg.Passwd = "123456";
        mysqlDBServerCfg.DBName = "EGEyesForVSS";
        mysqlDBServerCfg.DBConnCount = 5;
 
        LDBTool ldbTool;
        BaseSqliteDao::setLDBTool(&ldbTool);
 
        //#todo search from db
        Json::Value t_value;
        {
            LDBTool ldbTool;
            BaseSqliteDao::setLDBTool(&ldbTool);
            t_value = VssLocalSettingTblSqliteDao::instance()->findAllVssLocalSettingTblList();
        }
        if (t_value.size() == 1 && t_value["data"].size() > 1) {
            assert("t_value.size()");
        }
        DBG(t_value["data"].begin()->toStyledString());
        auto &t_cfg = *t_value["data"].begin();
        GBServerCfg gbServerCfg;
        gbServerCfg.SvrIp = t_cfg["ServerIp"].asString(); // 国标服务的ip地址  (本机的ip地址)
        gbServerCfg.SvrPort = atoi(t_cfg["ServerPort"].asString().c_str());// 7060; // 国标服务监听的端口
        gbServerCfg.SvrPubID = t_cfg["ServerId"].asString();// "44120000002000000001"; // 国标服务器的ID
        gbServerCfg.bMD5Auth = false; // 是否需要MD5加密
        gbServerCfg.UserName = t_cfg["UserAuthId"].asString();// "44120100002000000002"; // 国标服务的用户名    (下级设备注册的用户名)
        gbServerCfg.Passwd = t_cfg["Password"].asString();// "123456"; // 国标服务的密码    (下级设备注册的密码)
        gbServerCfg.SubScribeTime = 3600; // 订阅时间  如果为0 表示不订阅
 
        SpinLock spinLock;
 
        bool running = false;
        bool serinit = false;
        auto func = [&] {
            spinLock.lock();
            GB28181Server m_gbs;
            m_gbs.setMysqlConnParam(mysqlDBServerCfg);
            m_gbs.setGBServerParam(gbServerCfg);
            DBG("initServer start before");
            running = true;
            m_gbs.initServer();
            DBG("initServer start after");
 
            spinLock.unlock();
            while (running) {
                usleep(4000);
            }
        };
 
        std::thread thd(func);
        thd.detach();
 
        usleep(400);
        //      ---------------------测试------------------------
        spinLock.lock();
//    if (!running) {
//        ERR("running is false   <<   DB init error");
//        exit(0);
//    }
    }
    DBG("test start");
 
    appPref.setStringData("user.loop.absolute.path", appConfig.getStringProperty("cutPath"));
    IceRpcServer<RtspAnalysManager> server("RtspAnalysServer", appPref.getIntData("RpcServerPort"), "tcp");
    server.setMessageSizeMax(1024 * 1024 * 50);
    server.setPoolInitSize(1);
    server.setPoolMaxSize(1);
    server.runWaitShutDown();
    return 0;
 
}