lichao
2021-04-15 c64c54d8e75b9354dc49a7b6b2d326e7dd59eb37
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
/*
 * =====================================================================================
 *
 *       Filename:  center_main.cc
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  2021年04月13日 16时16分26秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Li Chao (), lichao@aiotlink.com
 *   Organization:  
 *
 * =====================================================================================
 */
#include "app_arg.h"
#include "box.h"
#include "center.h"
#include "defs.h"
#include "signalhandle.h"
#include <chrono>
#include <thread>
using namespace std::chrono_literals;
 
int center_main(int argc, const char *argv[])
{
    AppArg args(argc, argv);
    if (args.Has("remove")) {
        BHomeShm().Remove();
        return 0;
    }
 
    bool run = true;
    auto showStatus = [&]() {
        auto init = BHomeShm().get_free_memory();
        uint64_t idx = 0;
        while (run) {
            std::this_thread::sleep_for(1s);
            printf("%8d shared memory: avail : %ld / %ld\n", ++idx, BHomeShm().get_free_memory(), init);
        }
    };
    std::thread t(showStatus);
 
    BHCenter center(BHomeShm());
    center.Start();
    printf("center started ...\n");
    WaitForSignals({SIGINT, SIGTERM});
    run = false;
    t.join();
    return 0;
}
 
namespace
{
static bool install = BoxInstall("bhshmq_center", center_main, "bhome center program.");
}