// Return the Channel corresponding to the provided name Channel::Ptr Manager::get(const char* apChannelName) { Channel::Ptr ChannelPtr; Channel::Map::iterator iChannelPtr = mChannelMap.find(apChannelName); if (mChannelMap.end() != iChannelPtr) { ChannelPtr = iChannelPtr->second; } else { /// @todo Add a basic thread-safety security (throw if multiple threads create Loggers) ChannelPtr.reset(new Channel(apChannelName, mDefaultLevel)); mChannelMap[apChannelName] = ChannelPtr; } return ChannelPtr; }
void * logging_thread(void *arg) { Channel::Ptr ch; ch.reset(static_cast<Channel *>(arg)); /* casting argument */ print(log_debug, "Start logging thread for %s-api. Running as daemon: %s", ch->name(), ch->apiProtocol().c_str(), options.daemon() ? "yes" : "no"); // create configured api-interface vz::ApiIF::Ptr api; if (ch->apiProtocol() == "mysmartgrid") { api = vz::ApiIF::Ptr(new vz::api::MySmartGrid(ch, ch->options())); print(log_debug, "Using MSG-Api.", ch->name()); } else { api = vz::ApiIF::Ptr(new vz::api::Volkszaehler(ch, ch->options())); print(log_debug, "Using default api:", ch->name()); } //pthread_cleanup_push(&logging_thread_cleanup, &api); do { /* start thread mainloop */ try { ch->wait(); api->send(); } catch (std::exception &e) { print(log_error, "logging thread failed due to: %s", ch->name(), e.what()); } } while (options.logging()); print(log_debug, "Stop logging.! (daemon=%d)", ch->name(), options.daemon()); pthread_exit(0); //pthread_cleanup_pop(1); return NULL; }