示例#1
0
int main()
{
	SET_LOG_LEVEL(DEBUG);

	// ignored
	log(DEBUG,"I'm at main().\n");


	// printed
	log(INFO,"plus5(5) = %d\n",plus5AAAABBBBCCCC(5));


	log(INFO,"You shouldn't see me\n");
	log(WARN,"Change debug Level Successful\n");

	SET_LOG_LEVEL(DEBUG);

    log(DEBUG,"QQ\n");

    log(ERROR,"Bye\n");

	log(INFO,"You shouldn't see me\n");

	return 0;
}
示例#2
0
int main(int argc, char* argv[]) {
  QApplication app(argc, argv);
  app.setOrganizationName(PROJECT_COMPANYNAME);
  app.setOrganizationDomain(PROJECT_COMPANYNAME_DOMAIN);
  app.setApplicationName(PROJECT_NAME);
  app.setApplicationVersion(PROJECT_VERSION);
  app.setAttribute(Qt::AA_UseHighDpiPixmaps);
  app.setWindowIcon(fastonosql::gui::GuiFactory::instance().logoIcon());  // default icon for app
#ifdef NDEBUG
  SET_LOG_LEVEL(common::logging::L_INFO);
#else
  SET_LOG_LEVEL(common::logging::L_DEBUG);
#endif

  fastonosql::gui::MainWindow win;
  QRect screenGeometry = app.desktop()->availableGeometry();
  QSize screenSize(screenGeometry.width(), screenGeometry.height());

#ifdef OS_ANDROID
  win.resize(screenSize);
#else
  QSize size(screenGeometry.width() / 2, screenGeometry.height() / 2);
  if (preferedSize.height() <= screenSize.height() && preferedSize.width() <= screenSize.width()) {
    win.resize(preferedSize);
  } else {
    win.resize(size);
  }

  QPoint center = screenGeometry.center();
  win.move(center.x() - win.width() * 0.5, center.y() - win.height() * 0.5);
#endif

  win.show();
  return app.exec();
}
示例#3
0
 GlobalConfig() {
     /* We need to initialize JNI and our logging */
     SET_LOG_LEVEL(warning);
     #if (!_IS_MACOSX_I386_)
         JNI_INITIALIZE();        
     #endif
 }
示例#4
0
/**
 * Load configuration.
 */
void ServerContextImpl::loadConfiguration()
{
    Configuration::shared_pointer config = getConfiguration();

    // TODO for now just a simple switch
    int32 debugLevel = config->getPropertyAsInteger(PVACCESS_DEBUG, 0);
    if (debugLevel > 0)
        SET_LOG_LEVEL(logLevelDebug);

    // TODO multiple addresses
    _ifaceAddr.ia.sin_family = AF_INET;
    _ifaceAddr.ia.sin_addr.s_addr = htonl(INADDR_ANY);
    _ifaceAddr.ia.sin_port = 0;
    config->getPropertyAsAddress("EPICS_PVAS_INTF_ADDR_LIST", &_ifaceAddr);

    _beaconAddressList = config->getPropertyAsString("EPICS_PVA_ADDR_LIST", _beaconAddressList);
    _beaconAddressList = config->getPropertyAsString("EPICS_PVAS_BEACON_ADDR_LIST", _beaconAddressList);

    _autoBeaconAddressList = config->getPropertyAsBoolean("EPICS_PVA_AUTO_ADDR_LIST", _autoBeaconAddressList);
    _autoBeaconAddressList = config->getPropertyAsBoolean("EPICS_PVAS_AUTO_BEACON_ADDR_LIST", _autoBeaconAddressList);

    _beaconPeriod = config->getPropertyAsFloat("EPICS_PVA_BEACON_PERIOD", _beaconPeriod);
    _beaconPeriod = config->getPropertyAsFloat("EPICS_PVAS_BEACON_PERIOD", _beaconPeriod);

    _serverPort = config->getPropertyAsInteger("EPICS_PVA_SERVER_PORT", _serverPort);
    _serverPort = config->getPropertyAsInteger("EPICS_PVAS_SERVER_PORT", _serverPort);
    _ifaceAddr.ia.sin_port = htons(_serverPort);

    _broadcastPort = config->getPropertyAsInteger("EPICS_PVA_BROADCAST_PORT", _broadcastPort);
    _broadcastPort = config->getPropertyAsInteger("EPICS_PVAS_BROADCAST_PORT", _broadcastPort);

    _receiveBufferSize = config->getPropertyAsInteger("EPICS_PVA_MAX_ARRAY_BYTES", _receiveBufferSize);
    _receiveBufferSize = config->getPropertyAsInteger("EPICS_PVAS_MAX_ARRAY_BYTES", _receiveBufferSize);

    _channelProviderNames = config->getPropertyAsString("EPICS_PVA_PROVIDER_NAMES", _channelProviderNames);
    _channelProviderNames = config->getPropertyAsString("EPICS_PVAS_PROVIDER_NAMES", _channelProviderNames);

    //
    // introspect network interfaces
    //

    SOCKET sock = epicsSocketCreate(AF_INET, SOCK_STREAM, 0);
    if (!sock) {
        THROW_BASE_EXCEPTION("Failed to create a socket needed to introspect network interfaces.");
    }

    if (discoverInterfaces(_ifaceList, sock, &_ifaceAddr))
    {
        THROW_BASE_EXCEPTION("Failed to introspect network interfaces.");
    }
    else if (_ifaceList.size() == 0)
    {
        THROW_BASE_EXCEPTION("No (specified) network interface(s) available.");
    }
    epicsSocketDestroy(sock);
}
示例#5
0
文件: config.cpp 项目: Zhanyin/taomee
/**
 * @brief 加载 so 的所有配置
 *
 * return: -1: 错误, 0: 成功;
 */
int init_config(void)
{
/* MYTEST(zog): 测试 不分时log 和 TRACE_TLOG */
#if 1
	SET_TIME_SLICE_SECS(0);
	SET_LOG_LEVEL(tlog_lvl_trace);
#endif

	return 0;
}
示例#6
0
extern "C" int init_service(int isparent)
{
    if (isparent) {

    } else {
	/* MYTEST(zog): 测试 不分时log 和 TRACE_TLOG */
#if 1
		SET_TIME_SLICE_SECS(0);
		SET_LOG_LEVEL(tlog_lvl_trace);
#endif
        setup_timer();
        clear_online();
    }

    return 0;
}
示例#7
0
文件: main.c 项目: sevennothing/lros
int main(int argc, char** argv)
{
	int c;
	char *ubus_socket = UBUS_UNIX_SOCKET;

#ifdef LOG_LEVEL_DEFAULT
	LOG_INIT(APP_NAME, LOG_LEVEL_DEFAULT, STDOUT);
#else
	LOG_INIT(APP_NAME, LR_LOG_INFO, STDOUT);
#endif

	while((c = getopt(argc, argv, "dl:")) != -1)
	{
		switch (c)
		{
			case 'd':
				become_daemon = 0;
				break;
			case 'l':
				{
					char *end;
					long l;
					l = strtoul(optarg, &end, 0);
					if(*optarg == 0 || *end != 0 || l > 10)
					{
						ERROR(DEFAULT_GROUP,"Invalid loglevel %s", optarg);
						exit(1);
					}
					SET_LOG_LEVEL(l);
					break;
				}
			default:
				return -1;
		}
	}

	if(become_daemon){
		LOG_MODE(SYSLOG);
		openlog(APP_NAME, LOG_CONS | LOG_PID, LOG_LOCAL1);
		be_daemon();
	}

	lpd_setup_signals();

	pthread_create(&lpd_thread_id, NULL, (void *)loop_detect_run, NULL);

	if (loop_detect_ubus_init(ubus_socket) < 0) {
		ERROR(DEFAULT_GROUP, "failed to connect to ubus\n");
		return -1;
	}

	
	loop_detect_ubus_run();

	pthread_cancel(lpd_thread_id);
	pthread_join(lpd_thread_id, NULL);

	return 0;


}
示例#8
0
文件: OIUC.cpp 项目: mocidis/oiuc-v1
void OIUC::prepare() {

    /*---------------- ICS  -----------------*/
    ics_pool_init(&app_data.ics);
    ics_pjsua_init(&app_data.ics);
    ics_init(&app_data.ics);

    //qDebug() << "INIT DONE";
#if 1
    SET_LOG_LEVEL(4);
    pj_log_set_level(3);

    ics_set_default_callback(&on_reg_start_default);
    ics_set_reg_start_callback(&on_reg_start_impl);
    ics_set_reg_state_callback(&on_reg_state_impl);
    ics_set_incoming_call_callback(&on_incoming_call_impl);
    ics_set_call_state_callback(&on_call_state_impl);
    ics_set_call_transfer_callback(&on_call_transfer_impl);
    ics_set_call_media_state_callback(&on_call_media_state_impl);

    ics_start(&app_data.ics);
    config->getPortAsterisk(); // Don't need anymore, now set default bind to any port
    ics_connect(&app_data.ics, config->getPortAsterisk());

    qDebug() << "ICS STARTED";
#endif
    /*---------------- PTTC  -----------------*/
#if 0
    pttc_init(&app_data.serial, &app_data.pttc, on_pttc_ptt, app_data.ics.pool);
    pttc_start(&app_data.serial, config->getSerialFile().toLocal8Bit().data());
#endif
    /*---------------- NODE  -----------------*/
#if 1
    memset(&app_data.node, 0, sizeof(app_data.node));

    gm_cs = "udp:" + config->getArbiterIP() + ":" + QString::number(config->getPortSendToArbiter());
    gmc_cs = "udp:" + config->getOIUCIP() + ":" + QString::number(config->getPortOIUCListen());
    adv_cs = "udp:0.0.0.0:2015";

    init_adv_server(&app_data, adv_cs.toLocal8Bit().data(), &app_data.node, app_data.ics.pool);
    app_data.node.on_leaving_server_f = &on_leaving_server;
    node_init(&app_data.node,
              config->getOIUCName().toLocal8Bit().data(),
              config->getLocation().toLocal8Bit().data(),
              config->getOIUCDescription().toLocal8Bit().data(),
              -1,
              gm_cs.toLocal8Bit().data(),
              gmc_cs.toLocal8Bit().data(),
              app_data.ics.pool);
    node_add_adv_server(&app_data.node, &app_data.adv_server);

    qDebug() << "NODE INIT DONE";
#endif
    /*---------------- GB  -----------------*/
#if 1
    memset(&app_data.gr, 0, sizeof(app_data.gr));
    app_data.gr.on_online_report_f = &on_online_report;
    app_data.gr.on_tx_report_f = &on_tx_report;
    app_data.gr.on_rx_report_f = &on_rx_report;
    app_data.gr.on_sq_report_f = &on_sq_report;
    gb_receiver_init(&app_data.gr, (char *)GB_CS, app_data.ics.pool);

    qDebug() << "GB DONE";
#endif
    /*---------------- STREAM  -----------------*/
#if 1
    node_media_config(&app_data.node, &app_data.streamer, &app_data.receiver);
    app_data.node.streamer->pool = app_data.node.receiver->pool = app_data.ics.pool;
    app_data.node.streamer->ep = app_data.node.receiver->ep = pjsua_get_pjmedia_endpt();
    pjmedia_codec_g711_init(app_data.node.streamer->ep);
    pjmedia_codec_g711_init(app_data.node.receiver->ep);

    streamer_init(app_data.node.streamer, app_data.node.streamer->ep, app_data.node.streamer->pool);
    receiver_init(app_data.node.receiver, app_data.node.receiver->ep, app_data.node.receiver->pool, config->getNumberChannels());

    streamer_config_dev_source(app_data.node.streamer, config->getSoundStreamerIdx());
    receiver_config_dev_sink(app_data.node.receiver, config->getSoundReceiverIdx());
    //streamer_config_dev_source(app_data.node.streamer, 2);
    //receiver_config_dev_sink(app_data.node.receiver, 2);
    //qDebug() << "STREAM INIT...DONE\n";
#endif
}
示例#9
0
文件: riuc4.c 项目: mocidis/riuc-v1
int main(int argc, char *argv[]) {
    if (argc < 3) {
        usage(argv[0]);
    }

    /*------------ CONFIG VARIABLES ------------*/
    sqlite3 *db;
    char *sql, sql_cmd[100];
    sqlite3_stmt *stmt;

    char id[10], location[30], desc[50];
    char gm_cs[50], gmc_cs[50], adv_cs[50], gb_cs[50];
    char gm_cs_tmp[50], gmc_cs_tmp[50], adv_cs_tmp[50];

    int snd_dev_r0, snd_dev_r1, snd_dev_r2, snd_dev_r3;

    int adv_port = ADV_PORT;
    int gb_port = GB_PORT; 

    /*------------ INIT & STREAM VARIABLES ------------*/
    pj_caching_pool cp;
    pj_pool_t *pool;
    pjmedia_endpt *ep;

    endpoint_t streamers[MAX_NODE];
    endpoint_t receivers[MAX_NODE];
    adv_server_t adv_server;
    
    /*------------ OTHER VARIABLES ------------*/
    pthread_t thread;
    char *dummy, option[10];
    int i, n, input, f_quit = 0;
    int snd_dev[4];

    /*-----------------------------------------*/

    SET_LOG_LEVEL(4);

    /*------------ START ------------*/
#if 1
    SHOW_LOG(3, "Press '1': Set sound devices configure\nPress 's': Show databases\nPress 'Space': Load databases\nPress 'q': Quit\n");

    CALL_SQLITE (open (argv[2], &db));
    while(!f_quit) {
        dummy = fgets(option, sizeof(option), stdin);
        switch(option[0]) {
            case '1':
                SHOW_LOG(3, "Set device index for each radio...\n");
                for (i = 0; i < MAX_NODE; i++){
                    SHOW_LOG(3, "Radio %d: ", i);
                    dummy = fgets(option, sizeof(option), stdin);           
                    input = atoi(&option[0]);
                    n = sprintf(sql_cmd, "UPDATE riuc_config SET snd_dev_r%d =(?)", i);
                    sql_cmd[n] = '\0';
                    CALL_SQLITE (prepare_v2 (db, sql_cmd, strlen (sql_cmd) + 1, & stmt, NULL));
                    CALL_SQLITE (bind_int (stmt, 1, input));
                    CALL_SQLITE_EXPECT (step (stmt), DONE);
                }
                SHOW_LOG(3, "Config completed\n");               
                f_quit = 1;
                break;
            case 's':
                sql = "SELECT *FROM riuc_config";
                CALL_SQLITE (prepare_v2 (db, sql, strlen (sql) + 1, &stmt, NULL));

                while (sqlite3_step(stmt) == SQLITE_ROW) {
                    printf("ID: %s\n", sqlite3_column_text(stmt, 0));
                    printf("Location: %s\n", sqlite3_column_text(stmt, 1));
                    printf("Desc: %s\n", sqlite3_column_text(stmt, 2));
                    printf("GM_CS: %s\n", sqlite3_column_text(stmt, 3));
                    printf("GMC_CS: %s\n", sqlite3_column_text(stmt, 4));
                    printf("snd_dev_r0: %u\n", sqlite3_column_int(stmt, 5));
                    printf("snd_dev_r1: %u\n", sqlite3_column_int(stmt, 6));
                    printf("snd_dev_r2: %u\n", sqlite3_column_int(stmt, 7));
                    printf("snd_dev_r3: %u\n", sqlite3_column_int(stmt, 8));
                }
                break;
            case ' ':
                f_quit = 1;
                break;
            case 'q':
                return 0;
            default:
                SHOW_LOG(3, "Unknown option\n");
        }
    }
    f_quit = 0;
#endif
    /*------------ LOAD CONFIG ------------*/
    //CALL_SQLITE (open ("databases/riuc.db", &db));
    sql = "SELECT * FROM riuc_config";
    CALL_SQLITE (prepare_v2 (db, sql, strlen (sql) + 1, &stmt, NULL));

    //WARNING: MAX NUMBER OF SOUND DEV = 4
    while (sqlite3_step(stmt) == SQLITE_ROW) {
        strcpy(id, sqlite3_column_text(stmt, 0));
        strcpy(location, sqlite3_column_text(stmt, 1));
        strcpy(desc, sqlite3_column_text(stmt, 2));
        strcpy(gm_cs, sqlite3_column_text(stmt, 3));
        strcpy(gmc_cs, sqlite3_column_text(stmt, 4));
        snd_dev_r0 = sqlite3_column_int(stmt, 5);
        snd_dev_r1 = sqlite3_column_int(stmt, 6);
        snd_dev_r2 = sqlite3_column_int(stmt, 7);
        snd_dev_r3 = sqlite3_column_int(stmt, 8);
        auto_invite = sqlite3_column_int(stmt, 9);
    }

    snd_dev[0] = snd_dev_r0;
    snd_dev[1] = snd_dev_r1;
    snd_dev[2] = snd_dev_r2;
    snd_dev[3] = snd_dev_r3;

    n = sprintf(adv_cs, "udp:0.0.0.0:%d", adv_port);
    adv_cs[n] = '\0';
    n = sprintf(gb_cs, "udp:%s:%d",GB_MIP, gb_port);
    gb_cs[n] = '\0';
    
    SHOW_LOG(3, "========= LOADED CONFIG ========\n");
    SHOW_LOG(3, "ID: %s\nDesc: %s\nGM_CS: %s\nGMC_CS: %s\nADV_CS: %s\nGB_CS: %s\nsnd_r0: %d\nsnd_r1: %d\nsnd_r2: %d\nsnd_r3: %dAuto invite: %d\n", id, desc, gm_cs, gmc_cs, adv_cs, gm_cs, snd_dev_r0, snd_dev_r1, snd_dev_r2, snd_dev_r3, auto_invite);
    SHOW_LOG(3, "================================\n");

    /*------------ INIT ------------*/
    pj_init();
    pj_caching_pool_init(&cp, NULL, 10000);
    pool = pj_pool_create(&cp.factory, "pool1", 1024, 1024, NULL);

    SHOW_LOG(2, "INIT CP AND POOL...DONE\n");

    /*------------ NODE ------------*/
#if 1

    init_adv_server(&adv_server, adv_cs, pool);

    for (i = 0;i < MAX_NODE; i++) {
        memset(gm_cs_tmp, 0, sizeof(gm_cs_tmp));
        memset(gmc_cs_tmp, 0, sizeof(gmc_cs_tmp));
        memset(adv_cs_tmp, 0, sizeof(adv_cs_tmp));

        ansi_copy_str(gm_cs_tmp, gm_cs);
        ansi_copy_str(adv_cs_tmp, adv_cs);
        ansi_copy_str(gmc_cs_tmp, gmc_cs);

        n = strlen(gmc_cs);

        gmc_cs_tmp[n-1] = i + 1+ '0';

        memset(&riuc_data.node[i], 0, sizeof(riuc_data.node[i]));
        riuc_data.node[i].on_leaving_server_f = &on_leaving_server;
        node_init(&riuc_data.node[i], id, location, desc, i, gm_cs_tmp, gmc_cs_tmp, pool);
        node_add_adv_server(&riuc_data.node[i], &adv_server);
    }

    SHOW_LOG(2, "INIT NODE...DONE\n");
#endif
    /*----------- GB --------------*/
#if 1
    memset(&riuc_data.gb_sender, 0, sizeof(riuc_data.gb_sender));
    n = sprintf(gb_cs, "udp:%s:%d", GB_MIP, GB_PORT);
    gb_cs[n] = '\0';
    gb_sender_create(&riuc_data.gb_sender, gb_cs);

    SHOW_LOG(2, "INIT GB SENDER...DONE\n");
#endif
    /*----------- RIUC4 --------------*/
#if 1
    memset(riuc_data.serial_file, 0, sizeof(riuc_data.serial_file));
    strncpy(riuc_data.serial_file, argv[1], strlen(argv[1]));
    riuc4_init(&riuc_data.serial, &riuc_data.riuc4, &on_riuc4_status, pool);
    riuc4_start(&riuc_data.serial, riuc_data.serial_file);

    SHOW_LOG(2, "INIT RIUC4...DONE\n");
#if 1
    for (i = 0; i < MAX_NODE; i++) {
        riuc4_enable_rx(&riuc_data.riuc4, i);
        usleep(250*1000);
        riuc4_enable_tx(&riuc_data.riuc4, i);
        usleep(250*1000);
    }
#endif
    SHOW_LOG(2, "ENABLE TX & RX...DONE\n");
#endif
    /*----------- STREAM --------------*/
#if 1
    SHOW_LOG(3, "INIT STREAM...START\n");
    pjmedia_endpt_create(&cp.factory, NULL, 1, &ep);
#if 1
    SHOW_LOG(3, "CODEC INIT\n");
    pjmedia_codec_g711_init(ep);

    for (i = 0; i < MAX_NODE; i++) {
        SHOW_LOG(3, "NODE MEDIA CONFIG\n");
        node_media_config(&riuc_data.node[i], &streamers[i], &receivers[i]);
        SHOW_LOG(3, "SET POOL\n");
        riuc_data.node[i].streamer->pool = pool;
        riuc_data.node[i].receiver->pool = pool;
        
        SHOW_LOG(3, "SET ENDPOINT\n");
        riuc_data.node[i].receiver->ep = ep;
        riuc_data.node[i].streamer->ep = ep;

        SHOW_LOG(3, "INIT STREAMER & RECEIVER FOR NODE %d\n", i);
        streamer_init(riuc_data.node[i].streamer, riuc_data.node[i].streamer->ep, riuc_data.node[i].receiver->pool);
        receiver_init(riuc_data.node[i].receiver, riuc_data.node[i].receiver->ep, riuc_data.node[i].receiver->pool, 2);
    }
    
    SHOW_LOG(3, "CONFIG SOUND DEVICE\n");
    for (i = 0; i < MAX_NODE; i++) {
        streamer_config_dev_source(riuc_data.node[i].streamer, snd_dev[i]);
        receiver_config_dev_sink(riuc_data.node[i].receiver, snd_dev[i]);
    }

    SHOW_LOG(2, "INIT STREAM...DONE\n");
    /*---------------------------------*/
    pthread_create(&thread, NULL, auto_register, &riuc_data);
#endif
#endif
    while(!f_quit) {
        dummy = fgets(option, sizeof(option), stdin);

        switch(option[0]) {
            case 'c':
                for (i = 0; i < MAX_NODE; i++){
                    SHOW_LOG(3, "Set device index for each radio...\nRadio %d: ", i);
                    dummy = fgets(option, sizeof(option), stdin);           
                    input = atoi(&option[0]);
                    n = sprintf(sql_cmd, "UPDATE riuc_config SET snd_dev_r%d =(?)", i);
                    sql_cmd[n] = '\0';
                    CALL_SQLITE (prepare_v2 (db, sql_cmd, strlen (sql_cmd) + 1, & stmt, NULL));
                    CALL_SQLITE (bind_int (stmt, 1, input));
                    CALL_SQLITE_EXPECT (step (stmt), DONE);

                    streamer_config_dev_source(riuc_data.node[i].streamer, input);
                    receiver_config_dev_sink(riuc_data.node[i].receiver, input);
                }


                SHOW_LOG(3, "Config completed\n");               
                break;
            case 's':
                sql = "SELECT *FROM riuc_config";
                CALL_SQLITE (prepare_v2 (db, sql, strlen (sql) + 1, &stmt, NULL));

                while (sqlite3_step(stmt) == SQLITE_ROW) {
                    printf("ID: %s\n", sqlite3_column_text(stmt, 0));
                    printf("Location: %s\n", sqlite3_column_text(stmt, 1));
                    printf("Desc: %s\n", sqlite3_column_text(stmt, 2));
                    printf("GM_CS: %s\n", sqlite3_column_text(stmt, 3));
                    printf("GMC_CS: %s\n", sqlite3_column_text(stmt, 4));
                    printf("snd_dev_r0: %u\n", sqlite3_column_int(stmt, 5));
                    printf("snd_dev_r1: %u\n", sqlite3_column_int(stmt, 6));
                    printf("snd_dev_r2: %u\n", sqlite3_column_int(stmt, 7));
                    printf("snd_dev_r3: %u\n", sqlite3_column_int(stmt, 8));
                }
                break;
            case 't':
                node_start_session(&riuc_data.node[0]);
                break;
            case 'y':
                node_stop_session(&riuc_data.node[0]);
                break;
            case 'j':
                node_invite(&riuc_data.node[0], "FTW");
                break;
            case 'l':
                node_repulse(&riuc_data.node[0], "FTW");
                break;
            case 'q':
                f_quit = 1;
                break;
            default:
                SHOW_LOG(3, "Unknown option\n"); 
                break;
        }   

    }
    SHOW_LOG(3, "Quiting...\n");
    //pthread_join(thread, NULL);

    sqlite3_finalize(stmt);
    sqlite3_close(db);

    return 0;
}
示例#10
0
文件: main.c 项目: sevennothing/lros
/************************************************************************
函数名      服务主函数
************************************************************************/
int main(int argc, char *argv[])
{
    int c;
    int ret = 0;
    char *ubus_socket = UBUS_UNIX_SOCKET;

#ifdef LOG_LEVEL_DEFAULT
    LOG_INIT(SERVICE_NAME, LOG_LEVEL_DEFAULT, STDOUT);
#else
    LOG_INIT(SERVICE_NAME, LR_LOG_INFO, STDOUT);
#endif

    while((c = getopt(argc, argv, "dl:")) != -1)
    {
        switch (c)
        {
        case 'd':
            become_daemon = 0;
            break;
        case 'l':
        {
            char *end;
            long l;
            l = strtoul(optarg, &end, 0);
            if(*optarg == 0 || *end != 0 || l > 10)
            {
                ERROR(GLOBAL_OUT_GROUP,"Invalid loglevel %s", optarg);
                exit(1);
            }
            SET_LOG_LEVEL(l);
            wpa_set_debug_level(l);
            break;
        }
        default:
            return -1;
        }
    }

    if(become_daemon) {
        LOG_MODE(SYSLOG);
        openlog(SERVICE_NAME, LOG_CONS | LOG_PID, LOG_LOCAL1);
        /* Init to daemonize */
        daemonize();
    }

    int err = pthread_create(&nas_thread_id, NULL, (void *)nasd_run, NULL);
    if (err != 0) {
        ERROR(GLOBAL_OUT_GROUP, "can't create thread: %s\n", strerror(err));
        return -1;
    }

    if (nasd_ubus_init(ubus_socket) < 0) {
        ERROR(GLOBAL_OUT_GROUP, "failed to connect to ubus\n");
        pthread_cancel(nas_thread_id);
        pthread_join(nas_thread_id, NULL);
        return -1;
    }

    nasd_ubus_run();

    pthread_cancel(nas_thread_id);
    pthread_join(nas_thread_id, NULL);


    return 0;
}
示例#11
0
文件: mstpd.c 项目: sevennothing/lros
int main(int argc, char *argv[])
{
	int c;
	char *ubus_socket = UBUS_UNIX_SOCKET;
#if 0
	/* Sanity check */
	{
		bridge_identifier_t BridgeIdentifier;
		mst_configuration_identifier_t MST_ConfigurationIdentifier;
		TST(sizeof(BridgeIdentifier) == 8, -1);
		TST(sizeof(BridgeIdentifier.u) == 8, -1);
		TST(sizeof(BridgeIdentifier.s) == 8, -1);
		TST(sizeof(BridgeIdentifier.s.priority) == 2, -1);
		TST(sizeof(BridgeIdentifier.s.mac_address) == 6, -1);
		TST(sizeof(MST_ConfigurationIdentifier) == 51, -1);
		TST(sizeof(MST_ConfigurationIdentifier.a) == 51, -1);
		TST(sizeof(MST_ConfigurationIdentifier.s) == 51, -1);
#ifdef HMAC_MDS_TEST_FUNCTIONS
		TST(MD5TestSuite(), -1);
#endif /* HMAC_MDS_TEST_FUNCTIONS */
		INFO(GLOBAL_OUT_GROUP,"Sanity checks succeeded");
	}
#endif
#ifdef LOG_LEVEL_DEFAULT
	LOG_INIT("mstpd", LOG_LEVEL_DEFAULT, STDOUT);
#else
	LOG_INIT("mstpd", LR_LOG_INFO, STDOUT);
#endif

	while((c = getopt(argc, argv, "dl:")) != -1)
	{
		switch (c)
		{
			case 'd':
				become_daemon = 0;
				break;
			case 'l':
				{
					char *end;
					long l;
					l = strtoul(optarg, &end, 0);
					if(*optarg == 0 || *end != 0 || l > 10)
					{
						ERROR(GLOBAL_OUT_GROUP,"Invalid loglevel %s", optarg);
						exit(1);
					}
					SET_LOG_LEVEL(l);
					break;
				}
			default:
				return -1;
		}
	}

	if(become_daemon){
		LOG_MODE(SYSLOG);
		openlog(SERVICE_NAME, LOG_CONS | LOG_PID, LOG_LOCAL1);
		be_daemon();
	}

	mstpd_setup_signals();

	int ret,stacksize = 204800;
	pthread_attr_t attr;
	ret = pthread_attr_init(&attr); /*初始化线程属性*/

	if (ret != 0){
		return -1;
	}

	ret = pthread_attr_setstacksize(&attr, stacksize);

	if(ret != 0){
		pthread_attr_destroy(&attr);
		return -1;
	}

	ret = pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
	if(ret != 0){
		pthread_attr_destroy(&attr);
		return -1;
	}

#if 1
	struct sched_param param;
	param.sched_priority  = 90;
	ret = pthread_attr_setschedparam(&attr, &param);
	if(ret != 0){
		pthread_attr_destroy(&attr);
		return -1;
	}

#endif
	
	
	int err = pthread_create(&mstp_thread_id, &attr, (void *)mstpd_run, NULL);
	if (err != 0){
		ERROR(GLOBAL_OUT_GROUP, "can't create thread: %s\n", strerror(err));
		return -1;
	}

	if (mstpd_ubus_init(ubus_socket) < 0) {
		ERROR(GLOBAL_OUT_GROUP, "failed to connect to ubus\n");
		pthread_cancel(mstp_thread_id);
		pthread_join(mstp_thread_id, NULL);
		pthread_attr_destroy(&attr);
		return -1;
	}

	mstpd_ubus_run();

	pthread_cancel(mstp_thread_id);
	pthread_join(mstp_thread_id, NULL);
	pthread_attr_destroy(&attr);

	return 0;
}