lichao
2021-04-15 c64c54d8e75b9354dc49a7b6b2d326e7dd59eb37
box/center_main.cc
@@ -15,17 +15,40 @@
 *
 * =====================================================================================
 */
#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});
   // BHomeShm().Remove(); // remove ?
   run = false;
   t.join();
   return 0;
}