center::center(std::string filename, std::string key){ isrun = true; boost::shared_ptr<config::config> _config = boost::make_shared<config::config>(filename); if (_config == nullptr){ throw std::exception(("cannot find config file" + filename).c_str()); } auto center_config = _config->get_value_dict("center"); if (center_config == 0){ throw std::exception("cannot find center config"); } else{ try{ center_addr.first = center_config->get_value_string("ip"); center_addr.second = (short)center_config->get_value_int("port"); } catch(...){ throw std::exception("center config field error"); } } servernum = 0; _service = juggle::create_service(); _process = boost::make_shared<juggle::process>(); _channelservice = boost::make_shared<achieve::channelservice>(); _svrsessioncontainer = boost::make_shared<achieve::sessioncontainer>(_channelservice, _process); auto key_config = _config->get_value_dict("key"); if (key_config == 0){ throw std::exception("cannot find this config"); } else{ auto set = boost::make_shared<std::vector<std::pair<std::string, short> > >(); auto dict = _config->get_value_dict("blacklist"); for (size_t i = 0; i < dict->get_list_size(); i++){ auto e = dict->get_list_dict(i); auto ip = e->get_value_string("ip"); auto port = (short)e->get_value_int("port"); set->push_back(std::make_pair(ip, port)); } _writeacceptor = boost::make_shared<acceptor::writeacceptor>(key_config->get_value_string("ip"), key_config->get_value_int("port"), set, _channelservice, _svrsessioncontainer); } _timerservice = timer::timerservice::createinstance(); _module = boost::make_shared<module::center>(_process); _module->sigregister_db.connect(boost::bind(¢er::register_db, this, _1, _2)); _module->sigregister_gate.connect(boost::bind(¢er::register_gate, this, _1, _2)); _module->sigregister_routing.connect(boost::bind(¢er::register_routing, this, _1, _2)); _module->sigregister_logic.connect(boost::bind(¢er::register_logic, this, _1, _2)); }
logic::logic(std::string filename, std::string key) { isrun = true; boost::shared_ptr<config::config> _config = boost::make_shared<config::config>(filename); auto center_config = _config->get_value_dict("center"); if (center_config == 0) { throw std::exception("cannot find center config"); } else { try { center_addr.first = center_config->get_value_string("ip"); center_addr.second = (short)center_config->get_value_int("port"); } catch(...) { throw std::exception("center config field error"); } } _service = juggle::create_service(); _process = boost::make_shared<juggle::process>(); _channelservice = boost::make_shared<achieve::channelservice>(); _gatesessioncontainer = boost::make_shared<achieve::sessioncontainer>(_channelservice, _process); _gatesessioncontainer->sigdisconn.connect(boost::bind(&logic::gate_disconn, this, _1)); _gateconnector = boost::make_shared<connector::connector>(_channelservice, _gatesessioncontainer); _dbsessioncontainer = boost::make_shared<achieve::sessioncontainer>(_channelservice, _process); _dbsessioncontainer->sigdisconn.connect(boost::bind(&logic::db_disconn, this, _1)); _dbconnector = boost::make_shared<connector::connector>(_channelservice, _dbsessioncontainer); _timerservice = timer::timerservice::createinstance(); _module = boost::make_shared<module::logic>(_process); _module->sigregister_gate.connect(boost::bind(&logic::register_gate, this, _1, _2, _3)); _module->sigregister_db.connect(boost::bind(&logic::register_db, this, _1, _2, _3)); _module->sigregister_user.connect(boost::bind(&logic::register_user, this, _1)); _module->sigunregister_user.connect(boost::bind(&logic::unregister_user, this, _1)); _centersessioncontainer = boost::make_shared<achieve::sessioncontainer>(_channelservice, _process); _centerconnector = boost::make_shared<connector::connector>(_channelservice, _centersessioncontainer); add_timer(60 * 1000, boost::bind(&logic::keeplive_check, this, _1)); }
gate::gate(std::string filename, std::string key){ isrun = true; boost::shared_ptr<config::config> _config = boost::make_shared<config::config>(filename); auto center_config = _config->get_value_dict("center"); if (center_config == 0){ throw std::exception("cannot find center config"); } else{ try{ center_addr.first = center_config->get_value_string("ip"); center_addr.second = (short)center_config->get_value_int("port"); } catch(...){ throw std::exception("center config field error"); } } auto routing_config = _config->get_value_dict("routing"); if (routing_config == 0){ throw std::exception("cannot find routing config"); } else{ try{ auto size = routing_config->get_list_size(); routing_server.resize(size); for (uint32_t i = 0; i < size; i++){ auto cfig = routing_config->get_list_dict(i); routing_server[cfig->get_value_int("serial ")].first.first = cfig->get_value_string("ip"); routing_server[cfig->get_value_int("serial ")].first.second = cfig->get_value_int("port"); routing_server[cfig->get_value_int("serial ")].second = nullptr; } } catch (...){ throw std::exception("routing config field error"); } } _service = juggle::create_service(); _channelservice = boost::make_shared<achieve::channelservice>(); _rpcproxy = boost::make_shared<rpcproxy>(boost::bind(&gate::get_channel, this, _1, _2)); _usersessioncontainer = boost::make_shared<achieve::sessioncontainer>(_channelservice, _rpcproxy); _usersessioncontainer->sigdisconn.connect(boost::bind(&gate::user_disconn, this, _1)); _process = boost::make_shared<juggle::process>(); _logicsessioncontainer = boost::make_shared<achieve::sessioncontainer>(_channelservice, _process); _logicsessioncontainer->sigconn.connect(boost::bind(&gate::on_logic_conn, this, _1)); _logicsessioncontainer->sigdisconn.connect(boost::bind(&gate::logic_disconn, this, _1)); auto gate_config = _config->get_value_dict("key"); if (gate_config == 0){ throw std::exception("cannot find this config"); } else{ auto set = boost::make_shared<std::vector<std::pair<std::string, short> > >(); auto dict = _config->get_value_dict("blacklist"); for (size_t i = 0; i < dict->get_list_size(); i++){ auto e = dict->get_list_dict(i); auto ip = e->get_value_string("ip"); auto port = (short)e->get_value_int("port"); set->push_back(std::make_pair(ip, port)); } _blackacceptor = boost::make_shared<acceptor::blackacceptor>(gate_config->get_value_string("ip"), gate_config->get_value_int("port"), set, _channelservice, _usersessioncontainer); auto writeset = boost::make_shared<std::vector<std::pair<std::string, short> > >(); auto writedict = _config->get_value_dict("writelist"); for (size_t i = 0; i < dict->get_list_size(); i++){ auto e = writedict->get_list_dict(i); auto ip = e->get_value_string("ip"); auto port = (short)e->get_value_int("port"); writeset->push_back(std::make_pair(ip, port)); } _writeacceptor = boost::make_shared<acceptor::writeacceptor>(gate_config->get_value_string("clusterip"), gate_config->get_value_int("clusterport"), writeset, _channelservice, _logicsessioncontainer); } _timerservice = timer::timerservice::createinstance(); _module = boost::make_shared<module::gate>(_process); _routingsessioncontainer = boost::make_shared<achieve::sessioncontainer>(_channelservice, _process); _routingconnector = boost::make_shared<connector::connector>(_channelservice, _routingsessioncontainer); _centersessioncontainer = boost::make_shared<achieve::sessioncontainer>(_channelservice, _process); _centerconnector = boost::make_shared<connector::connector>(_channelservice, _centersessioncontainer); }
void main(int argc, char * argv[]) { auto svr_uuid = boost::lexical_cast<std::string>(boost::uuids::random_generator()()); if (argc <= 1) { std::cout << "non input start argv" << std::endl; return; } std::string config_file_path = argv[1]; auto _config = boost::make_shared<config::config>(config_file_path); if (argc >= 3) { _config = _config->get_value_dict(argv[2]); } boost::shared_ptr<juggle::process> _svr_process = boost::make_shared<juggle::process>(); boost::shared_ptr<center::svrmanager> _svrmanager = boost::make_shared<center::svrmanager>(); boost::shared_ptr<center::logicsvrmanager> _logicsvrmanager = boost::make_shared<center::logicsvrmanager>(); boost::shared_ptr<module::center> _center = boost::make_shared<module::center>(); _center->sigreg_serverhandle.connect(boost::bind(®_server, _svrmanager, _logicsvrmanager, _1, _2, _3, _4)); _svr_process->reg_module(_center); boost::shared_ptr<module::logic_call_center> _logic_call_center = boost::make_shared<module::logic_call_center>(); _logic_call_center->sigreq_get_server_addresshandle.connect(boost::bind(&req_get_server_address, _logicsvrmanager, _svrmanager, _1, _2)); _svr_process->reg_module(_logic_call_center); auto host_ip = _config->get_value_string("ip"); auto host_port = (short)_config->get_value_int("port"); auto _host_service = boost::make_shared<service::acceptnetworkservice>(host_ip, host_port, _svr_process); boost::shared_ptr<center::gmmanager> _gmmanager = boost::make_shared<center::gmmanager>(); boost::shared_ptr<juggle::process> _gm_process = boost::make_shared<juggle::process>(); boost::shared_ptr<module::gm_center> _gm_center = boost::make_shared<module::gm_center>(); _gm_center->sigconfirm_gmhandle.connect(boost::bind(&confirm_gm, _gmmanager, _1)); _gm_center->sigclose_clutterhandle.connect(boost::bind(&close_clutter, _gmmanager, _svrmanager, _1)); _gm_process->reg_module(_gm_center); auto gm_ip = _config->get_value_string("gm_ip"); auto gm_port = (short)_config->get_value_int("gm_port"); auto _gm_service = boost::make_shared<service::acceptnetworkservice>(gm_ip, gm_port, _gm_process); boost::shared_ptr<service::juggleservice> _juggleservice = boost::make_shared<service::juggleservice>(); _juggleservice->add_process(_svr_process); _juggleservice->add_process(_gm_process); int64_t tick = clock(); int64_t tickcount = 0; boost::shared_ptr<service::timerservice> _timerservice = boost::make_shared<service::timerservice>(tick); while (true) { int64_t tmptick = (clock() & 0xffffffff); if (tmptick < tick) { tickcount += 1; tmptick = tmptick + tickcount * 0xffffffff; } tick = tmptick; try { _host_service->poll(tick); _gm_service->poll(tick); _juggleservice->poll(tick); _timerservice->poll(tick); } catch (std::exception e) { std::cout << "system exception:" << e.what() << std::endl; break; } tmptick = (clock() & 0xffffffff); if (tmptick < tick) { tickcount += 1; tmptick = tmptick + tickcount * 0xffffffff; } int64_t ticktime = (tmptick - tick); tick = tmptick; if (ticktime < 50) { boost::this_thread::sleep(boost::posix_time::microseconds(15)); } } }
void main(int argc, char * argv[]) { auto svr_uuid = boost::lexical_cast<std::string>(boost::uuids::random_generator()()); if (argc <= 1) { std::cout << "non input start argv" << std::endl; return; } std::string config_file_path = argv[1]; auto _config = boost::make_shared<config::config>(config_file_path); auto _center_config = _config->get_value_dict("center"); if (argc >= 3) { _config = _config->get_value_dict(argv[2]); } int64_t tick = clock(); int64_t tickcount = 0; boost::shared_ptr<service::timerservice> _timerservice = boost::make_shared<service::timerservice>(tick); boost::shared_ptr<juggle::process> _center_process = boost::make_shared<juggle::process>(); auto _connectnetworkservice = boost::make_shared<service::connectnetworkservice>(_center_process); auto center_ip = _center_config->get_value_string("ip"); auto center_port = (short)_center_config->get_value_int("port"); auto _center_ch = _connectnetworkservice->connect(center_ip, center_port); auto _centerproxy = boost::make_shared<gate::centerproxy>(_center_ch); auto inside_ip = _config->get_value_string("inside_ip"); auto inside_port = (short)_config->get_value_int("inside_port"); _centerproxy->reg_server(inside_ip, inside_port, svr_uuid); boost::shared_ptr<gate::closehandle> _closehandle = boost::make_shared<gate::closehandle>(); auto _center_call_server = boost::make_shared<module::center_call_server>(); _center_call_server->sigreg_server_sucesshandle.connect(boost::bind(®_server_sucess, _centerproxy)); _center_call_server->sigclose_serverhandle.connect(boost::bind(&close_server, _closehandle)); _center_process->reg_module(_center_call_server); auto _logic_process = boost::make_shared<juggle::process>(); auto _logic_call_gate = boost::make_shared<module::logic_call_gate>(); auto _logicsvrmanager = boost::make_shared<gate::logicsvrmanager>(); auto _clientmanager = boost::make_shared<gate::clientmanager>(); _logic_call_gate->sigreg_logichandle.connect(boost::bind(®_logic, _logicsvrmanager, _1)); _logic_call_gate->sigack_client_connect_serverhandle.connect(boost::bind(&ack_client_connect_server, _logicsvrmanager, _clientmanager, _timerservice, _1, _2)); _logic_call_gate->sigforward_logic_call_clienthandle.connect(boost::bind(&forward_logic_call_client, _clientmanager, _1, _2, _3, _4)); _logic_call_gate->sigforward_logic_call_group_clienthandle.connect(boost::bind(&forward_logic_call_group_client, _clientmanager, _1, _2, _3, _4)); _logic_call_gate->sigforward_logic_call_global_clienthandle.connect(boost::bind(&forward_logic_call_global_client, _clientmanager, _1, _2, _3)); _logic_process->reg_module(_logic_call_gate); auto _logic_service = boost::make_shared<service::acceptnetworkservice>(inside_ip, inside_port, _logic_process); _timerservice->addticktime(tick + 5 * 60 * 1000, boost::bind(&heartbeat_handle, _clientmanager, _timerservice, _1)); auto _client_process = boost::make_shared<juggle::process>(); auto _client_call_gate = boost::make_shared<module::client_call_gate>(); _client_call_gate->sigconnect_serverhandle.connect(boost::bind(&connect_server, _logicsvrmanager, _clientmanager, _timerservice, _1)); _client_call_gate->sigcancle_serverhandle.connect(boost::bind(&cancle_server, _clientmanager)); _client_call_gate->sigforward_client_call_logichandle.connect(boost::bind(&forward_client_call_logic, _clientmanager, _1, _2, _3)); _client_call_gate->sigheartbeatshandle.connect(boost::bind(&heartbeats, _clientmanager, _timerservice)); _client_process->reg_module(_client_call_gate); auto outside_ip = _config->get_value_string("outside_ip"); auto outside_port = (short)_config->get_value_int("outside_port"); auto _client_service = boost::make_shared<service::acceptnetworkservice>(outside_ip, outside_port, _client_process); boost::shared_ptr<service::juggleservice> _juggleservice = boost::make_shared<service::juggleservice>(); _juggleservice->add_process(_center_process); _juggleservice->add_process(_logic_process); _juggleservice->add_process(_client_process); while (true) { int64_t tmptick = (clock() & 0xffffffff); if (tmptick < tick) { tickcount += 1; tmptick = tmptick + tickcount * 0xffffffff; } tick = tmptick; _connectnetworkservice->poll(tick); _juggleservice->poll(tick); if (_centerproxy->is_reg_sucess) { _logic_service->poll(tick); _client_service->poll(tick); _timerservice->poll(tick); } if (_closehandle->is_closed) { std::cout << "server closed, gate server " << svr_uuid << std::endl; break; } tmptick = (clock() & 0xffffffff); if (tmptick < tick) { tickcount += 1; tmptick = tmptick + tickcount * 0xffffffff; } int64_t ticktime = (tmptick - tick); tick = tmptick; if (ticktime < 50) { boost::thread::sleep(boost::get_system_time() + boost::posix_time::microseconds(15)); } } }
void main(int argc, char * argv[]) { auto svr_uuid = boost::lexical_cast<std::string>(boost::uuids::random_generator()()); if (argc <= 1) { std::cout << "non input start argv" << std::endl; return; } std::string config_file_path = argv[1]; auto _config = boost::make_shared<config::config>(config_file_path); auto _center_config = _config->get_value_dict("center"); if (argc >= 3) { _config = _config->get_value_dict(argv[2]); } boost::shared_ptr<juggle::process> _center_process = boost::make_shared<juggle::process>(); boost::shared_ptr<service::connectnetworkservice> _connectnetworkservice = boost::make_shared<service::connectnetworkservice>(_center_process); auto center_ip = _center_config->get_value_string("ip"); auto center_port = (short)_center_config->get_value_int("port"); auto _center_ch = _connectnetworkservice->connect(center_ip, center_port); boost::shared_ptr<dbproxy::centerproxy> _centerproxy = boost::make_shared<dbproxy::centerproxy>(_center_ch); auto ip = _config->get_value_string("ip"); auto port = (short)_config->get_value_int("port"); _centerproxy->reg_server(ip, port, svr_uuid); boost::shared_ptr<dbproxy::closehandle> _closehandle = boost::make_shared<dbproxy::closehandle>(); boost::shared_ptr<module::center_call_server> _center_call_server = boost::make_shared<module::center_call_server>(); _center_call_server->sigclose_serverhandle.connect(boost::bind(&close_server, _closehandle)); _center_call_server->sigreg_server_sucesshandle.connect(boost::bind(®_server_sucess, _centerproxy)); _center_process->reg_module(_center_call_server); auto db_ip = _config->get_value_string("db_ip"); auto db_port = (short)_config->get_value_int("db_port"); auto db_name = _config->get_value_string("db_name"); auto db_collection = _config->get_value_string("db_collection"); auto _mongodb_proxy = boost::make_shared<dbproxy::mongodb_proxy>(db_ip, db_port, db_name, db_collection); boost::shared_ptr<juggle::process> _dbthings_process = boost::make_shared<juggle::process>(); boost::shared_ptr<module::logic_call_dbproxy> _logic_call_dbproxy = boost::make_shared<module::logic_call_dbproxy>(); boost::shared_ptr<dbproxy::logicsvrmanager> _logicsvrmanager = boost::make_shared<dbproxy::logicsvrmanager>(); _logic_call_dbproxy->sigreg_logichandle.connect(boost::bind(®_logic, _logicsvrmanager, _closehandle, _1)); _logic_call_dbproxy->siglogic_closedhandle.connect(boost::bind(&logic_closed, _closehandle)); _logic_call_dbproxy->sigcreate_persisted_objecthandle.connect(boost::bind(&logic_create_persisted_object, _logicsvrmanager, _mongodb_proxy, _1, _2)); _logic_call_dbproxy->sigupdata_persisted_objecthandle.connect(boost::bind(&logic_updata_persisted_object, _logicsvrmanager, _mongodb_proxy, _1, _2, _3)); _logic_call_dbproxy->sigget_object_infohandle.connect(boost::bind(&logic_get_object_info, _logicsvrmanager, _mongodb_proxy, _1, _2)); _dbthings_process->reg_module(_logic_call_dbproxy); boost::shared_ptr<module::hub_call_dbproxy> _hub_call_dbproxy = boost::make_shared<module::hub_call_dbproxy>(); boost::shared_ptr<dbproxy::hubsvrmanager> _hubsvrmanager = boost::make_shared<dbproxy::hubsvrmanager>(); _hub_call_dbproxy->sigreg_hubhandle.connect(boost::bind(®_hub, _hubsvrmanager, _closehandle, _1)); _hub_call_dbproxy->sigcreate_persisted_objecthandle.connect(boost::bind(&hub_create_persisted_object, _hubsvrmanager, _mongodb_proxy, _1, _2)); _hub_call_dbproxy->sigupdata_persisted_objecthandle.connect(boost::bind(&hub_updata_persisted_object, _hubsvrmanager, _mongodb_proxy, _1, _2, _3)); _hub_call_dbproxy->sigget_object_infohandle.connect(boost::bind(&hub_get_object_info, _hubsvrmanager, _mongodb_proxy, _1, _2)); _dbthings_process->reg_module(_hub_call_dbproxy); auto _acceptnetworkservice = boost::make_shared<service::acceptnetworkservice>(ip, port, _dbthings_process); boost::shared_ptr<service::juggleservice> _juggleservice = boost::make_shared<service::juggleservice>(); _juggleservice->add_process(_center_process); _juggleservice->add_process(_dbthings_process); int64_t tick = clock(); int64_t tickcount = 0; boost::shared_ptr<service::timerservice> _timerservice = boost::make_shared<service::timerservice>(tick); while (true) { int64_t tmptick = (clock() & 0xffffffff); if (tmptick < tick) { tickcount += 1; tmptick = tmptick + tickcount * 0xffffffff; } tick = tmptick; if (_centerproxy->is_reg_sucess) { _acceptnetworkservice->poll(tick); } _connectnetworkservice->poll(tick); _juggleservice->poll(tick); _timerservice->poll(tick); if (_closehandle->is_close()) { std::cout << "server closed, dbproxy server " << svr_uuid << std::endl; break; } tmptick = (clock() & 0xffffffff); if (tmptick < tick) { tickcount += 1; tmptick = tmptick + tickcount * 0xffffffff; } int64_t ticktime = (tmptick - tick); tick = tmptick; Sleep(15); } }
gate::gate(std::string filename, std::string key){ isrun = true; boost::shared_ptr<config::config> _config = boost::make_shared<config::config>(filename); auto center_config = _config->get_value_dict("center"); if (center_config == 0){ throw std::exception("cannot find center config"); } else{ try{ center_addr.first = center_config->get_value_string("ip"); center_addr.second = (short)center_config->get_value_int("port"); } catch(...){ throw std::exception("center config field error"); } } auto routing_config = _config->get_value_dict("routing"); if (routing_config == 0){ throw std::exception("cannot find routing config"); } else{ try{ auto size = routing_config->get_list_size(); routing_server.resize(size); for (uint32_t i = 0; i < size; i++){ auto cfig = routing_config->get_list_dict(i); routing_server[cfig->get_value_int("serial ")].first.first = cfig->get_value_string("ip"); routing_server[cfig->get_value_int("serial ")].first.second = cfig->get_value_int("port"); routing_server[cfig->get_value_int("serial ")].second = nullptr; } } catch (...){ throw std::exception("routing config field error"); } } _service = juggle::create_service(); _channelservice = boost::make_shared<achieve::channelservice>(); _rpcproxy = boost::make_shared<rpcproxy>(boost::bind(&gate::get_channel, this, _1, _2)); _usersessioncontainer = boost::make_shared<achieve::sessioncontainer>(_channelservice, _rpcproxy); _usersessioncontainer->sigdisconn.connect(boost::bind(&gate::user_disconn, this, _1)); auto gate_config = _config->get_value_dict("key"); if (gate_config == 0){ throw std::exception("cannot find this config"); } else{ _blackacceptor = boost::make_shared<acceptor::blackacceptor>(gate_config, _channelservice, _usersessioncontainer); } _timerservice = timer::timerservice::createinstance(); _process = boost::make_shared<juggle::process>(); _module = boost::make_shared<module::gate>(_process); _module->sigregister_logic.connect(boost::bind(&gate::add_logic, this, _1, _2)); _logicsessioncontainer = boost::make_shared<achieve::sessioncontainer>(_channelservice, _process); _logicconnector = boost::make_shared<connector::connector>(_channelservice, _logicsessioncontainer); _routingsessioncontainer = boost::make_shared<achieve::sessioncontainer>(_channelservice, _process); _routingconnector = boost::make_shared<connector::connector>(_channelservice, _routingsessioncontainer); _centersessioncontainer = boost::make_shared<achieve::sessioncontainer>(_channelservice, _process); _centerconnector = boost::make_shared<connector::connector>(_channelservice, _centersessioncontainer); }
int INI::get_value_int(const chowstring & item, int def) { return get_value_int(current_group, item, def); }