예제 #1
0
bool ApService::InitApService(std::string ApListenIp, int ApListenPort, int threadPoolNum) {
    bool status = true;

    _ApListenIp = ApListenIp;
    _ApListenPort = ApListenPort;
    _threadPoolNum = threadPoolNum;

    SharedPointer<IProcessor> xp(
        new apapiProcessor(
            SharedPointer<apapi>(
                new ApService)));

    ServiceManager sm;
    sm.add_service(xp);

    ThreadPool tp;
    tp.init(_threadPoolNum);
    Server* server = new Server(&sm, &tp, _ApListenPort);

    if (0 != server->serve()) {
        status =  false;
    }

    return status;
}
예제 #2
0
파일: server.cpp 프로젝트: AresDice/BGCC
void* server_func(const bool* isstopped, void*)
{
    SharedPointer<IProcessor> xp(
            new ManyClientsProcessor(
                SharedPointer<ManyClients>(
                    new ManyClientsImpl)));

    ServiceManager sm;
    sm.add_service(xp);

    ThreadPool tp;
    tp.init(10);
    Server* server = new Server(&sm, &tp, 8321);
    if (0 != server->serve()) {
        return 0;
    }
    return NULL;
}
예제 #3
0
파일: server.cpp 프로젝트: AresDice/BGCC
int main( int argc, char **argv){
	
	log_open("server.cfg");

	SharedPointer<IProcessor> proc_send(
			new demo::CallbackSenderProcessor(
				SharedPointer<callback_send_impl_t> (new callback_send_impl_t) ));

	ServiceManager mgr;
	mgr.add_service(proc_send);

	ThreadPool pool;
	pool.init(POOL_SIZE);

	Server server(&mgr,&pool,LISTEN_PORT);

	SharedPointer<Thread> thrd(new Thread( SharedPointer<Runnable>( new  callback_send_thrd_t  )));
	thrd->start();

	server.serve();

	return 0;
}
예제 #4
0
int main(int argc, char** argv) {

    signal(SIGPIPE, SIG_IGN);

    char const* const short_options = "vh";
    struct option long_options[] = {
        { "version", 0, NULL, 'v'},
        { "help", 0, NULL, 'h'},
    };

    // is version command
    char ch = 0;

    while ((ch = getopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
        switch (ch) {
        case 'v':
            std::cout << VERSION << std::endl;
            return 0;

        case 'h':
            std::cout << "./{ims_server}& run ims_server" << std::endl;
            return 0;

        default:
            std::cerr << "ims_server --version";
            return 0;
        }
    }

    ims_session_manager_t* pmgr = ims_session_manager_t::instance();
    //读取配置
    ims_conf_t& conf = pmgr->config();

    if (!ims_conf_loader_t::instance()->load_conf(pmgr->pool(), conf)) {
        FATAL_LOG("load config file failed");
        return -1;
    }

    NOTICE_LOG("ims server starting(version : %s , build time : %s" , VERSION , BUILD_DATE);

    //open bgcc log
    std::string bgcclog = "bgcc.cfg";
    bgcc::log_open(bgcclog.c_str());
    TRACE_LOG("bgcc::log_open success!");

    fs_mgr_t::instance()->update_log(conf.gw_log);
    TRACE_LOG("load configure file ok");

    const char* tmp = NULL;

    if (conf.param.count(ICPT_MAXSESSION) != 0 && conf.param[ICPT_MAXSESSION] != NULL) {
        tmp = conf.param[ICPT_MAXSESSION];
        pmgr->maxsession((uint32_t)atoi(tmp));
    } else {
        pmgr->maxsession(2000);
    }

    TRACE_LOG("starting freeswitch manager...");
    //fs_mgr启动
    std::list<ims_conf_gw_node_t*>& gws = conf.gateway;
    ims_conf_gw_node_t* gw_node=NULL;

    for (std::list<ims_conf_gw_node_t*>::iterator it = gws.begin(); it != gws.end(); ++it) {
        if (*it) {
            gw_node = (*it);
            fs_info_t info(gw_node->id, gw_node->ip, gw_node->port, gw_node->max_conn,
                           gw_node->user, gw_node->pswd);

            if (IMS_SUCCESS != fs_mgr_t::instance()->add_fs(info)) {
                FATAL_LOG("load freeswitch(id=%u,ip=%u,port=%u,user=%s,pswd=%s) failed",
                          gw_node->id, gw_node->ip, gw_node->port, gw_node->user, gw_node->pswd);
                raise(SIGKILL);
            }

            TRACE_LOG("load freeswitch(%u,%u:%u) success", gw_node->id,  gw_node->ip, gw_node->port);
        }
    }

    //session thread_mgr start
    //
    TRACE_LOG("starting ims session thread pool...");
    session_thrd_mgr::instance()->start();

    TRACE_LOG("starting ims api service...");

    //启动主服务bgcc的端口监听
    std::map<ims_conf_service_type_t, ims_conf_server_t*>& service
        = conf.service;

    ims_conf_server_t* pserver = NULL;

    if (service.count(ICST_MONITOR) != 0) {
        //TODO 启动监控
    } else {
        WARNING_LOG("monitor service not started");
    }

    if (service.count(ICST_CONFIG) != 0) {
        //TODO 启动配置接口
    } else {
        WARNING_LOG("config service not started(dynamic config will disabled)");
    }


    if (service.count(ICST_MAIN) != 0 && service[ICST_MAIN] != NULL) {
        pserver = service[ICST_MAIN];
        //TODO 启动主服务程序
        TRACE_LOG("starting ims api service on port :%d", pserver->port);
        SharedPointer<IProcessor> ims_proc(new imsapiProcessor(SharedPointer<imsapi>(new imsapi_impl_t)));

        ServiceManager sm;
        sm.add_service(ims_proc);

        ThreadPool tp;
        int pool_size = 500; //set default to 500
        const char* tmp_poolsize = NULL;

        if (conf.param.count(ICPT_BGCCPOOLSIZE) != 0 && conf.param[ICPT_BGCCPOOLSIZE] != NULL) {
            tmp_poolsize = conf.param[ICPT_BGCCPOOLSIZE];
            pool_size = atoi(tmp_poolsize);
        }

        //if(argc == 2){
        //    pool_size = std::max(pool_size, atoi(argv[1]));
        //    TRACE_LOG("main service thread pool size: %d", pool_size);
        //}
        if (pool_size <= 0) {
            WARNING_LOG("main service thread pool size: %d <= 0, exiting...", pool_size);
            raise(SIGKILL);
        }

        TRACE_LOG("main service thread pool size: %d", pool_size);
        tp.init(pool_size);
        Server* server = new Server(&sm, &tp, pserver->port);

        if (NULL == server || 0 != server->serve()) {
            WARNING_LOG("ims api service exiting...");
            delete server;
            raise(SIGKILL);
        }

        delete server;
    } else {
        FATAL_LOG("ims api service config error");
        return -1;
    }

    ///////////////////servcie run////////////////////

    //////////////////////////////////////////////////

    //////////////////service stop////////////////////
    fs_mgr_t::instance()->clear_fs();
    WARNING_LOG("after clear fs...");

    return 0;
}