#include #include #include #include #include #include #include #include #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; }