remove dependency on APR library
This commit is contained in:
+20
-83
@@ -25,15 +25,10 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
#include "cmdline.h"
|
||||
#include <string.h>
|
||||
#include <apr_general.h>
|
||||
#include <apr_getopt.h>
|
||||
#include "lds_hub.h"
|
||||
|
||||
/** Cmdline input broadcast code */
|
||||
@@ -42,82 +37,28 @@ static std::vector<std::string> cmdline_broadcast_code;
|
||||
/** Set the program options.
|
||||
* You can input the registered device broadcast code and decide whether to save the log file.
|
||||
*/
|
||||
static int SetProgramOption(int argc, const char *argv[]) {
|
||||
apr_status_t rv;
|
||||
apr_pool_t *mp = NULL;
|
||||
static const apr_getopt_option_t opt_option[] = {
|
||||
/** Long-option, short-option, has-arg flag, description */
|
||||
{ "code", 'c', 1, "Register device broadcast code" },
|
||||
{ "log", 'l', 0, "Save the log file" },
|
||||
{ "help", 'h', 0, "Show help" },
|
||||
{ NULL, 0, 0, NULL },
|
||||
};
|
||||
apr_getopt_t *opt = NULL;
|
||||
int optch = 0;
|
||||
const char *optarg = NULL;
|
||||
|
||||
if (apr_initialize() != APR_SUCCESS) {
|
||||
return -1;
|
||||
void SetProgramOption(int argc, const char *argv[]) {
|
||||
cmdline::parser cmd;
|
||||
cmd.add<std::string>("code", 'c', "Register device broadcast code", false);
|
||||
cmd.add("log", 'l', "Save the log file");
|
||||
cmd.add("help", 'h', "Show help");
|
||||
cmd.parse_check(argc, const_cast<char **>(argv));
|
||||
if (cmd.exist("code")) {
|
||||
std::string sn_list = cmd.get<std::string>("code");
|
||||
printf("Register broadcast code: %s\n", sn_list.c_str());
|
||||
cmdline_broadcast_code.clear();
|
||||
cmdline_broadcast_code.push_back(sn_list);
|
||||
}
|
||||
|
||||
if (apr_pool_create(&mp, NULL) != APR_SUCCESS) {
|
||||
return -1;
|
||||
if (cmd.exist("log")) {
|
||||
printf("Save the log file.\n");
|
||||
SaveLoggerFile();
|
||||
}
|
||||
|
||||
rv = apr_getopt_init(&opt, mp, argc, argv);
|
||||
if (rv != APR_SUCCESS) {
|
||||
printf("Program options initialization failed.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/** Parse the all options based on opt_option[] */
|
||||
bool is_help = false;
|
||||
while ((rv = apr_getopt_long(opt, opt_option, &optch, &optarg)) == APR_SUCCESS) {
|
||||
switch (optch) {
|
||||
case 'c': {
|
||||
printf("Register broadcast code: %s\n", optarg);
|
||||
cmdline_broadcast_code.clear();
|
||||
cmdline_broadcast_code.push_back(optarg);
|
||||
break;
|
||||
}
|
||||
case 'l': {
|
||||
printf("Save the log file.\n");
|
||||
SaveLoggerFile();
|
||||
break;
|
||||
}
|
||||
case 'h': {
|
||||
printf(
|
||||
" [-c] Register device broadcast code\n"
|
||||
" [-l] Save the log file\n"
|
||||
" [-h] Show help\n"
|
||||
);
|
||||
is_help = true;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (rv != APR_EOF) {
|
||||
printf("Invalid options.\n");
|
||||
}
|
||||
|
||||
apr_pool_destroy(mp);
|
||||
mp = NULL;
|
||||
apr_terminate();
|
||||
if (is_help)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
return;
|
||||
}
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
/** Set the program options. */
|
||||
if (SetProgramOption(argc, argv)) {
|
||||
return 0;
|
||||
}
|
||||
SetProgramOption(argc, argv);
|
||||
|
||||
LdsHub& read_hub = LdsHub::GetInstance();
|
||||
int ret = read_hub.InitLdsHub(cmdline_broadcast_code);
|
||||
@@ -129,11 +70,7 @@ int main(int argc, const char *argv[]) {
|
||||
|
||||
printf("Start discovering device.\n");
|
||||
|
||||
#ifdef WIN32
|
||||
Sleep(100000);
|
||||
#else
|
||||
sleep(100);
|
||||
#endif
|
||||
std::this_thread::sleep_for(std::chrono::seconds(100));
|
||||
|
||||
read_hub.DeInitLdsHub();
|
||||
printf("Livox hub demo end!\n");
|
||||
|
||||
Reference in New Issue
Block a user