int operator()(atapp::app &app, const atapp::app::msg_t &msg, const void *buffer, size_t len) { if (NULL == msg.body.forward || 0 == msg.head.src_bus_id) { WLOGERROR("receive a message from unknown source"); return app.get_bus_node()->send_data(msg.head.src_bus_id, msg.head.type, buffer, len); } switch (msg.head.type) { case ::atframe::component::service_type::EN_ATST_GATEWAY: { ::atframe::gw::ss_msg req_msg; msgpack::unpacked result; msgpack::unpack(result, reinterpret_cast<const char *>(buffer), len); msgpack::object obj = result.get(); if (obj.is_nil()) { return 0; } obj.convert(req_msg); switch (req_msg.head.cmd) { case ATFRAME_GW_CMD_POST: { // keep all data not changed and send back int res = app.get_bus_node()->send_data(msg.body.forward->from, 0, buffer, len); if (res < 0) { WLOGERROR("send back post data to 0x%llx failed, res: %d", static_cast<unsigned long long>(msg.body.forward->from), res); } else if (NULL != req_msg.body.post) { WLOGDEBUG("receive msg %s and send back to 0x%llx done", std::string(reinterpret_cast<const char *>(req_msg.body.post->content.ptr), req_msg.body.post->content.size).c_str(), static_cast<unsigned long long>(msg.body.forward->from)); } break; } case ATFRAME_GW_CMD_SESSION_ADD: { WLOGINFO("create new session 0x%llx, address: %s:%d", static_cast<unsigned long long>(req_msg.head.session_id), req_msg.body.session->client_ip.c_str(), req_msg.body.session->client_port); if (0 != req_msg.head.session_id) { (*gw_)[req_msg.head.session_id] = msg.body.forward->from; } break; } case ATFRAME_GW_CMD_SESSION_REMOVE: { WLOGINFO("remove session 0x%llx", static_cast<unsigned long long>(req_msg.head.session_id)); gw_->erase(req_msg.head.session_id); break; } default: WLOGERROR("receive a unsupport atgateway message of invalid cmd:%d", static_cast<int>(req_msg.head.cmd)); break; } break; } default: WLOGERROR("receive a message of invalid type:%d", msg.head.type); break; } return 0; }
int operator()(util::cli::callback_param params) { if (params.get_params_number() <= 0) { WLOGERROR("kickoff command must require session id"); return 0; } uint64_t sess_id = params[0]->to_uint64(); session_gw_map_t::iterator iter = gw_->find(sess_id); if (iter == gw_->end()) { WLOGWARNING("try to kickoff 0x%llx, but session not found", static_cast<unsigned long long>(sess_id)); return 0; } else { WLOGINFO("kickoff 0x%llx", static_cast<unsigned long long>(sess_id)); } ::atframe::gw::ss_msg msg; msg.init(ATFRAME_GW_CMD_SESSION_KICKOFF, sess_id); std::stringstream ss; msgpack::pack(ss, msg); std::string packed_buffer; ss.str().swap(packed_buffer); return app_->get_bus_node()->send_data(iter->second, 0, packed_buffer.data(), packed_buffer.size()); }
//======================================================================================================= void log_sample() { puts(""); puts("===============begin log sample=============="); WLOG_INIT(util::log::log_wrapper::categorize_t::DEFAULT, util::log::log_wrapper::level_t::LOG_LW_DEBUG); PSTDERROR("try to print error log.\n"); PSTDOK("try to print ok log.\n"); WLOGNOTICE("notice log %d", 0); util::log::log_sink_file_backend filed_backend; filed_backend.set_max_file_size(256); filed_backend.set_rotate_size(3); filed_backend.set_file_pattern("%Y-%m-%d/%S/%N.log"); // filed_backend.set_check_interval(1); WLOG_GETCAT(util::log::log_wrapper::categorize_t::DEFAULT)->add_sink(filed_backend); for (int i = 0; i < 16; ++i) { WLOGDEBUG("first dir test log: %d", i); } THREAD_SLEEP_MS(1000); util::time::time_utility::update(); for (int i = 0; i < 16; ++i) { WLOGDEBUG("second dir log: %d", i); } unsigned long long ull_test_in_mingw = 64; WLOGINFO("%llu", ull_test_in_mingw); printf("log are located at %s\n", util::file_system::get_cwd().c_str()); puts("===============end log sample=============="); }
int operator()(atapp::app &app, atbus::endpoint &ep, int status) { WLOGINFO("node 0x%llx disconnected, status: %d", static_cast<unsigned long long>(ep.get_id()), status); atproxy_mgr_module.get().on_disconnected(app, ep.get_id()); return 0; }
static int app_handle_on_disconnected(atapp::app &, atbus::endpoint &ep, int status) { WLOGINFO("app 0x%llx disconnected, status: %d", static_cast<unsigned long long>(ep.get_id()), status); return 0; }
static int app_handle_on_msg(atapp::app &, const atapp::app::msg_t &msg, const void *buffer, size_t len) { std::string data; data.assign(reinterpret_cast<const char *>(buffer), len); WLOGINFO("receive a message(from 0x%llx, type=%d) %s", static_cast<unsigned long long>(msg.head.src_bus_id), msg.head.type, data.c_str()); return 0; }
//======================================================================================================= void log_sample_func1(int times) { if (times > 0) { log_sample_func1(times - 1); return; } if (util::log::is_stacktrace_enabled()) { std::cout << "----------------test stacktrace begin--------------" << std::endl; char buffer[2048] = {0}; util::log::stacktrace_write(buffer, sizeof(buffer)); std::cout << buffer << std::endl; std::cout << "----------------test stacktrace end--------------" << std::endl; } WLOG_INIT(util::log::log_wrapper::categorize_t::DEFAULT, util::log::log_wrapper::level_t::LOG_LW_DEBUG); WLOG_GETCAT(util::log::log_wrapper::categorize_t::DEFAULT)->set_stacktrace_level(util::log::log_wrapper::level_t::LOG_LW_INFO); WLOG_GETCAT(util::log::log_wrapper::categorize_t::DEFAULT)->clear_sinks(); std::cout << "----------------setup log_wrapper done--------------" << std::endl; PSTDERROR("try to print error log.\n"); PSTDOK("try to print ok log.\n"); std::cout << "----------------sample for PSTDOK/PSTDERROR done--------------" << std::endl; WLOGNOTICE("notice log %d", 0); util::log::log_sink_file_backend filed_backend; filed_backend.set_max_file_size(256); filed_backend.set_rotate_size(3); filed_backend.set_file_pattern("%Y-%m-%d/%S/%N.log"); WLOG_GETCAT(util::log::log_wrapper::categorize_t::DEFAULT)->add_sink(filed_backend); std::cout << "----------------setup file system log sink done--------------" << std::endl; for (int i = 0; i < 16; ++i) { WLOGDEBUG("first dir test log: %d", i); } THREAD_SLEEP_MS(1000); util::time::time_utility::update(); for (int i = 0; i < 16; ++i) { WLOGDEBUG("second dir log: %d", i); } unsigned long long ull_test_in_mingw = 64; WLOGINFO("%llu", ull_test_in_mingw); WLOG_GETCAT(util::log::log_wrapper::categorize_t::DEFAULT) ->set_sink(WLOG_GETCAT(util::log::log_wrapper::categorize_t::DEFAULT)->sink_size() - 1, util::log::log_wrapper::level_t::LOG_LW_DEBUG, util::log::log_wrapper::level_t::LOG_LW_DEBUG); WLOGDEBUG("Debug still available %llu", ull_test_in_mingw); WLOGINFO("Info not available now %llu", ull_test_in_mingw); std::cout << "log are located at " << util::file_system::get_cwd().c_str() << std::endl; WLOG_GETCAT(util::log::log_wrapper::categorize_t::DEFAULT)->pop_sink(); WLOGERROR("No log sink now"); }