派生自 development/c++

pansen
2019-02-28 b6c9f1297932297dc37b957355faa21dba44e81d
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
#include <iostream>
#include <unistd.h>
#include <sys/time.h>
#include <vector>
#include <boost/interprocess/shared_memory_object.hpp>
#include <boost/interprocess/mapped_region.hpp>
 
#include <jsoncpp/json/json.h>
#include <thread>
 
#include "ErlangDbTool.h"
#include "ShareMemoryTool.hpp"
 
using namespace std;
 
//#erl -name b@192.168.1.164 -setcookie abc -mnesia dir '"/home/firefly/erlang"' -detached -noshell
int main(int argc, char **argv) {
    ENABLEGLOG(GET_STR_CONFIG("logPath").c_str());
    std::cout << "Hello, World!" << std::endl;
 
 
 
 
 
 
//    string str_json(argv[1]);
//0096ee77-1f50-48e2-a08a-42536a754970@192.168.1.124
//    string str_json = "{\"path\":\"/opt/erlang/0096ee77-1f50-48e2-a08a-42536a754970/\","
//                      "\"nodeName\":\"0096ee77-1f50-48e2-a08a-42536a754970@192.168.1.124\",\"cookie\":\"1234\","
//                      "\"tableName\":\"test\"}";
 
    string str_json = "{\"personList\":[{\"idcard\":\"www\",\"name\":\"www\",\"personId\":\"1532\",\"feature\":\"13dasd\"},"
                      "{\"idcard\":\"133310998877665544\",\"name\":\"测试教师-三班班主任\",\"personId\":\"1533\","
                      "\"feature\":\"13dasd\"}],\"uuid\":\"16011ab6-c966-5114-afa5-569c91f866c3\"}";
 
    Json::Value t_json;
    Json::Reader reader;
 
    if (!reader.parse(str_json, t_json)) {
        return -1;
    }
    string TableUuid = t_json["uuid"].asString();
    auto perlists = t_json["personList"];
 
    int lsize = perlists.size();
    for (int i = 0; i < lsize; ++i) {
//        perlists[0]
    }
    for (auto &item : perlists) {
        item["idcard"].asString();
        item["personId"].asString();
        item["feature"].asString();
        int i = 0;
    }
 
 
    return 0;
 
 
    std::string path = t_json["path"].asString();//"/opt/erlang/za/";
    std::string nodeName = t_json["nodeName"].asString();//"za@192.168.188.128";
    std::string cookie = t_json["cookie"].asString();//"abc";
    std::string tableName = t_json["tableName"].asString();
 
 
    ErlangTool::ErlangDbTool erlangDbTool(nodeName, cookie, "test");
 
 
//    bool ret = erlangDbTool.initErlang();
    ErlangTool::map_FaceDataCache cache;
 
    std::thread thread1([&] {
        while (1) {
            /***
             * jiazai renlian
             */
            struct timeval t1, t2;
            gettimeofday(&t1, NULL);
 
            /***
             * load fea
             */
            cache = erlangDbTool.loadFaceFeaData(tableName);
 
            gettimeofday(&t2, NULL);
            //那么函数f运行所花的时间为
            auto deltaT = (t2.tv_sec - t1.tv_sec) * 1000000 + t2.tv_usec - t1.tv_usec;
            std::cout << __FILE__ << __LINE__ << " deltaT " << deltaT << "us  size is " << cache.size() << std::endl;
 
        }
    });
 
    std::thread thread2([&] {
        while (1) {
            /***
             * jiazai renlian
             */
            struct timeval t1, t2;
            gettimeofday(&t1, NULL);
 
            /***
             * load fea
             */
            auto cache2 = erlangDbTool.findAllNode();
 
            gettimeofday(&t2, NULL);
            //那么函数f运行所花的时间为
            auto deltaT = (t2.tv_sec - t1.tv_sec) * 1000000 + t2.tv_usec - t1.tv_usec;
            std::cout << __FILE__ << __LINE__ << " deltaT " << deltaT << "us  size is " << cache2.size() << std::endl;
 
        }
    });
 
 
    auto size = sizeof(cache[0]) * cache.size();
 
    try {
 
        BISTL::shared_memory_object::remove(tableName.c_str());
 
        BISTL::BiMapFeaData biMapFeaData(tableName, size);
 
        for (auto &item :cache) {
            biMapFeaData.saveKeyOrValue(item.second.id.c_str(), item.second.feature.c_str(),
                                        item.second.create_by.c_str(),
                                        item.second.create_time.c_str(), item.second.update_time.c_str());
        }
 
//        auto mymap = biMapFeaData.getMap();
//        for (auto it = mymap->begin(); it != mymap->end(); it++) {
//            std::cout << "feature " << it->second.m_feature << std::endl;
//        }
        printf("\n");
 
    }
    catch (const std::exception &e) {
        printf("Exception:%s\n", e.what());
        BISTL::shared_memory_object::remove(tableName.c_str());
    }
    printf("getchar\n");
    getchar();
 
 
    return 0;
}