acl/app/wizard/wizard.cpp

99 lines
2.0 KiB
C++
Raw Normal View History

// wizard.cpp : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̨Ӧ<CCA8>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ㡣
2014-11-19 00:25:21 +08:00
//
#include "stdafx.h"
#include <stdio.h>
#if !defined(_WIN32) && !defined(_WIN64)
# include <getopt.h>
#endif
2014-11-19 00:25:21 +08:00
#include "master_creator.h"
#include "http_creator.h"
static void create_db()
{
}
static int create_master_service(const char* name, const char* type)
{
master_creator(name, type);
return 0;
}
static int create_http_service(const char* name, const char* type)
{
http_creator(name, type);
return 0;
}
static void usage(const char* procname)
{
printf("usage: %s -h [help]\r\n"
" -n program_name\r\n"
" -t service_type [ t -> master_threads, p -> master_proc, f -> master_fiber, u -> master_udp, o -> master_other ]\r\n"
" -a application_type [ http | master, default: master ]\r\n"
, procname);
}
2014-11-19 00:25:21 +08:00
int main(int argc, char* argv[])
{
int ch;
acl::string name, type, app("master");
while ((ch = getopt(argc, argv, "hn:t:a:")) > 0) {
switch (ch) {
case 'h':
usage(argv[0]);
return 0;
case 'n':
name = optarg;
break;
case 't':
type = optarg;
break;
case 'a':
app = optarg;
break;
default:
break;
}
}
2014-11-19 00:25:21 +08:00
acl::acl_cpp_init();
if (!name.empty() && !type.empty()) {
if (app == "master") {
return create_master_service(name, type);
} else if (app == "http") {
return create_http_service(name, type);
}
}
while (true) {
char buf[256];
2014-11-19 00:25:21 +08:00
printf("select one below:\r\n");
printf("m: master_service; d: db; h: http; q: exit\r\n");
printf(">"); fflush(stdout);
int n = acl_vstream_gets_nonl(ACL_VSTREAM_IN, buf, sizeof(buf));
if (n == ACL_VSTREAM_EOF) {
2014-11-19 00:25:21 +08:00
break;
}
if (strcasecmp(buf, "m") == 0) {
master_creator(NULL, NULL);
} else if (strcasecmp(buf, "d") == 0) {
2014-11-19 00:25:21 +08:00
create_db();
} else if (strcasecmp(buf, "h") == 0) {
http_creator(NULL, NULL);
} else if (strcasecmp(buf, "q") == 0) {
2014-11-19 00:25:21 +08:00
break;
} else {
2014-11-19 00:25:21 +08:00
printf("unknown %s\r\n", buf);
}
2014-11-19 00:25:21 +08:00
}
printf("Bye!\r\n");
return 0;
}