本文整理汇总了C++中SignalHandler类的典型用法代码示例。如果您正苦于以下问题:C++ SignalHandler类的具体用法?C++ SignalHandler怎么用?C++ SignalHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SignalHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: signal
/**
* Entry point into the thread.
*/
void* SignalThread::Run() {
sigset_t signals;
int signo;
#ifdef _WIN32
if (g_signal_map) {
OLA_WARN << "Windows signal map was already set, it will be overwritten.";
}
g_signal_map = &m_signal_handlers;
SignalMap::const_iterator iter = m_signal_handlers.begin();
for (; iter != m_signal_handlers.end(); ++iter) {
signal(iter->first, Win32SignalHandler);
}
#endif
while (true) {
#ifndef _WIN32
sigemptyset(&signals);
AddSignals(&signals);
// Don't try to use sigpending here. It won't work on Mac.
if (sigwait(&signals, &signo) != 0) {
OLA_INFO << "sigwait error: " << strerror(errno);
continue;
}
OLA_INFO << "Received signal: " << strsignal(signo);
SignalHandler *handler = STLFindOrNull(m_signal_handlers, signo);
if (handler) {
handler->Run();
}
#endif
}
return NULL;
}
示例2:
void * SignalHandler::DoSignalHandlingLoop(void * arg)
{
SignalHandler * self = (SignalHandler *) arg;
self->running = true;
self->SignalHandlingLoop();
return NULL;
}
示例3: _handleDialogResponseWithConnectObject
/**
* Handles all gtk dialog responses that include connect object by passing them
* off to a SignalHandler.
*
* @param dialog the dialog that sent the response.
* @param responseId the response ID.
* @param userData the user data pointer to the connect object to use.
*/
static void _handleDialogResponseWithConnectObject(
GtkDialog* dialog, gint responseId, gpointer userData)
{
// get signal handler out of connect object's user data map
GObject* connectObject = static_cast<GObject*>(userData);
gpointer ptr = g_object_get_data(connectObject, GOBJECT_KEY_HANDLER);
SignalHandler* h = static_cast<SignalHandler*>(ptr);
h->handleDialogResponse(dialog, responseId);
}
示例4: _handleWidgetEventWithConnectObject
/**
* Handles all gtk widget events that include connect object by passing them
* off to a SignalHandler.
*
* @param widget the widget to handle the event for.
* @param event the event to handle.
* @param userData the user data pointer to the connect object to use.
*/
static gboolean _handleWidgetEventWithConnectObject(
GtkWidget* widget, GdkEvent* event, gpointer userData)
{
// get signal handler out of connect object's user data map
GObject* connectObject = static_cast<GObject*>(userData);
gpointer ptr = g_object_get_data(connectObject, GOBJECT_KEY_HANDLER);
SignalHandler* h = static_cast<SignalHandler*>(ptr);
return h->handleWidgetEvent(widget, event) ? TRUE : FALSE;
}
示例5: _handleWidgetSignalWithConnectObject
/**
* Handles all gtk widget signals that include connect object by passing them
* off to a SignalHandler.
*
* @param widget the widget to handle the signal for.
* @param userData the user data pointer to the connect object to use.
*/
static void _handleWidgetSignalWithConnectObject(
GtkWidget* widget, gpointer userData)
{
// get signal handler out of connect object's user data map
GObject* connectObject = static_cast<GObject*>(userData);
gpointer ptr = g_object_get_data(connectObject, GOBJECT_KEY_HANDLER);
SignalHandler* h = static_cast<SignalHandler*>(ptr);
h->handleWidgetSignal(widget);
}
示例6: run
int run(int argc, char* argv[]) {
function_footprint();
ApplicationSetting setting;
// default value
setting.clusterConfig = "conf/cluster.conf";
if(!parseArguments(argc, argv, &setting)) {
usage(argv[0]);
return 1;
}
LOG(INFO) << "Start server with configuration: " << setting.clusterConfig;
idgs::Application& app = * idgs_application();
ResultCode rc;
DVLOG(1) << "Loading configuration.";
rc = app.init(setting.clusterConfig);
if (rc != RC_SUCCESS) {
LOG(ERROR) << "Failed to initialize server: " << getErrorDescription(rc);
exit(1);
}
DVLOG(1) << "Server is starting.";
rc = app.start();
if (rc != RC_SUCCESS) {
LOG(ERROR) << "Failed to start server: " << getErrorDescription(rc);
exit(1);
}
DVLOG(1) << "";
SignalHandler sh;
sh.setup();
LOG(INFO) << "=============================================================";
LOG(INFO) << "Server is started, please press ctrl-c to exit.";
LOG(INFO) << "=============================================================";
// dead loop
while(app.isRunning()) {
sleep(1);
monitor(app);
}
DVLOG(1) << "Server is shutting down.";
rc = app.stop();
if (rc != RC_SUCCESS) {
LOG(ERROR) << "Failed to start server: " << getErrorDescription(rc);
exit(1);
}
return 0;
}
示例7: vm_watch_signal
Object* System::vm_watch_signal(STATE, Fixnum* sig) {
SignalHandler* h = state->shared.signal_handler();
if(h) {
native_int i = sig->to_native();
if(i < 0) {
h->add_signal(-i, true);
} else {
h->add_signal(i);
}
return Qtrue;
} else {
return Qfalse;
}
}
示例8: sigfillset
void Environment::start_signals() {
#ifndef RBX_WINDOWS
struct sigaction action;
action.sa_handler = null_func;
action.sa_flags = 0;
sigfillset(&action.sa_mask);
sigaction(SIGVTALRM, &action, NULL);
#endif
state->set_run_signals(true);
SignalHandler* handler = new SignalHandler(state);
shared->set_signal_handler(handler);
handler->run(state);
#ifndef RBX_WINDOWS
// Ignore sigpipe.
signal(SIGPIPE, SIG_IGN);
// Some extensions expect SIGALRM to be defined, because MRI does.
// We'll just use a noop for it.
signal(SIGALRM, null_func);
// If we have execinfo, setup some crash handlers
#ifdef USE_EXECINFO
if(!getenv("DISABLE_SEGV")) {
signal(SIGSEGV, segv_handler);
signal(SIGBUS, segv_handler);
signal(SIGILL, segv_handler);
signal(SIGFPE, segv_handler);
signal(SIGABRT, segv_handler);
// Force glibc to load the shared library containing backtrace()
// now, so that we don't have to try and load it in the signal
// handler.
void* ary[1];
backtrace(ary, 1);
}
#endif // USE_EXEC_INFO
// Setup some other signal that normally just cause the process
// to terminate so that we print out a message, then terminate.
signal(SIGHUP, quit_handler);
signal(SIGUSR1, quit_handler);
signal(SIGUSR2, quit_handler);
#endif // ifndef RBX_WINDOWS
signal(SIGTERM, quit_handler);
}
示例9: main
int main(int argc,char *argv[])
{
try
{
try
{
init();
thread threadCar(threadServerCar);
thread threadWorker(threadServerWorker);
threadCar.detach();
threadWorker.detach();
try
{
SignalHandler signalHandler;
// Register signal handler to handle kill signal
signalHandler.setupSignalHandlers();
// Infinite loop until signal ctrl-c (KILL) received
while (!signalHandler.gotExitSignal())
{
std::this_thread::sleep_for(1s);
}
}
catch (SignalException& e)
{
std::cerr << "SignalException: " << e.what() << std::endl;
}
}
catch(boost::exception_ptr & e)
{
BOOST_LOG_TRIVIAL(fatal) << "boost fatal" << boost::diagnostic_information(e);
exit(-1);
}
}
catch (...)
{
BOOST_LOG_TRIVIAL(fatal) << "unknown fatal in main thread";
exit(-1);
}
return 0;
}
示例10: main
int main(int argc, char **argv)
{
// monitor startup performance
unsigned int startupTimeInMs = 0;
timeval start, end;
gettimeofday(&start, 0);
// collect all configuration settings
Configuration configuration(argc, argv);
// setup logging
Log::consoleLogLevel = (LOG_MODES)configuration.getLogLevelConsole();
Log::fileLogLevel = (LOG_MODES)configuration.getLogLevelFile();
Log::dltLogLevel = (LOG_MODES)configuration.getLogLevelTrace();
LOG_INFO("LayerManagerService", "Starting Layermanager (version: " << ILM_VERSION << ")");
// log configuration options
configuration.logAllSettings();
{
SignalHandler signalHandler;
Layermanager layermanager(configuration);
if (layermanager.startManagement())
{
gettimeofday(&end, 0);
startupTimeInMs = ((end.tv_sec - start.tv_sec) * 1000) + ((end.tv_usec - start.tv_usec) / 1000);
LOG_INFO("LayerManagerService", "Startup complete. EnterMainloop. " << startupTimeInMs << "ms");
signalHandler.waitForShutdownSignal();
LOG_DEBUG("LayerManagerService", "Stopping service.");
layermanager.stopManagement();
}
}
LOG_INFO("LayerManagerService", "Shutdown complete.");
Log::closeInstance();
return 0;
}
示例11: _connectSignals
/**
* Connect an object's signals to the appropriate handlers.
*
* @param builder the builder that created the object.
* @param object the object to connect.
* @param signalName the name of the signal to connect.
* @param handlerName the name of the handler to use.
* @param connectObject if non-NULL, use g_signal_connect_object.
* @param flags the connection flags to use.
* @param userData a pointer to mapping of signals to handler pointers.
*/
static void _connectSignals(
GtkBuilder* builder, GObject* object,
const gchar* signalName, const gchar* handlerName,
GObject* connectObject, GConnectFlags flags,
gpointer userData)
{
const char* hn = (const char*)handlerName;
// get controller's signal handler associated with handler name, log
// cases where there is no controller signal handler found
Controller* controller = static_cast<Controller*>(userData);
SignalHandler* h = controller->getSignalHandler(hn);
if(h != NULL)
{
SignalHandler::SignalType t = h->getSignalType();
GCallback cb = NULL;
if(connectObject != NULL)
{
switch(t)
{
case SignalHandler::WidgetSignal:
cb = G_CALLBACK(_handleWidgetSignalWithConnectObject);
break;
case SignalHandler::WidgetEvent:
cb = G_CALLBACK(_handleWidgetEventWithConnectObject);
break;
case SignalHandler::DialogResponse:
cb = G_CALLBACK(_handleDialogResponseWithConnectObject);
break;
}
// save handler in connect object
g_object_set_data(connectObject, GOBJECT_KEY_HANDLER, h);
g_signal_connect_object(object, signalName, cb, connectObject, flags);
}
else
{
switch(t)
{
case SignalHandler::WidgetSignal:
cb = G_CALLBACK(_handleWidgetSignal);
break;
case SignalHandler::WidgetEvent:
cb = G_CALLBACK(_handleWidgetEvent);
break;
case SignalHandler::DialogResponse:
cb = G_CALLBACK(_handleDialogResponse);
break;
}
// pass handler as data
g_signal_connect_data(object, signalName, cb, h, NULL, flags);
}
}
else
{
MO_CAT_WARNING(BM_GTKUI_CAT,
"No gtk signal handler found for '%s'", hn);
}
}
示例12: _handleDialogResponse
/**
* Handles all gtk dialog responses by passing them off to a SignalHandler.
*
* @param dialog the dialog that sent the response.
* @param responseId the response ID.
* @param userData the user data pointer to the SignalHandler to use.
*/
static void _handleDialogResponse(
GtkDialog* dialog, gint responseId, gpointer userData)
{
SignalHandler* h = static_cast<SignalHandler*>(userData);
h->handleDialogResponse(dialog, responseId);
}
示例13: main
int main (int argc, char** argv)
{
ArgParserLector& args = ArgParserLector::getInstance ();
args.parse (argc, argv);
if (args.fdBroker () == -1) {
LOG_IPCL(
"TODO: verificar si el lector podría abrir"
" la conexión hacia el broker; ver ordenamiento"
" de connects..");
return 1;
}
LOG_IPCL("Estableciendo manejador de señal SIGINT...");
SIGINT_Handler intHandler;
SignalHandler* sigs = SignalHandler::getInstance ();
sigs->registrarHandler (SIGINT, &intHandler);
LOG_IPCL("Conectando a IPCs...");
std::string pathColas = calcularPathColas (args);
IPCManager ipcman (args.idLocal (), args.mqInterfaz (), pathColas);
LOG_IPCL("Inicializando conexión con broker...");
long idPuerta = args.idPuerta ();
MensajeGenerico brokerMsg;
LOG_IPCL("Creando socket con mensaje de tamaño %llu.",
static_cast<unsigned long long> (sizeof brokerMsg));
cClientSocket brokerConn (sizeof brokerMsg);
brokerConn.tcp_adopt_connection (args.fdBroker ());
brokerMsg.mtype = 0;
brokerMsg.id = idPuerta;
LOG_IPCL("Paquete de inicialización:\n"
"\tdstId : %ld\n"
"\tsrcId : %ld",
brokerMsg.mtype,
brokerMsg.id);
brokerConn.tcp_send (reinterpret_cast<char*> (&brokerMsg));
LOG_IPCL("Enviado. Aguardando operaciones...");
while (intHandler.getGracefulQuit () == 0) {
try {
int err = brokerConn.tcp_recv (reinterpret_cast<char*> (&brokerMsg));
if (err == 0) { /* EOF: conexión cerrada... */
LOG_IPCL ("Conexión cerrada por el host remoto. Saliendo...");
break;
}
System::check (err);
LOG_IPCL ("Se recibió paquete desde el broker:\n"
"\tdstId : %ld\n"
"\tsrcId : %ld\n"
"\tmsg.op : %d (%s)\n"
"\tmsg.param_a : %ld\n"
"\tmsg.param_b : %ld\n"
"\tshm.abierto : %d\n"
"\tshm.capacidad: %d\n"
"\tshm.personas : %d",
brokerMsg.mtype,
brokerMsg.id,
brokerMsg.msg.op,
strMuseoMSGOP (brokerMsg.msg.op),
brokerMsg.msg.param_a,
brokerMsg.msg.param_b,
brokerMsg.shmem.abierto,
brokerMsg.shmem.capacidad,
brokerMsg.shmem.personas);
IPersonaMsg msg;
msg.op = static_cast<IPersonaOp> (brokerMsg.msg.op);
switch (brokerMsg.msg.op) {
case MuseoMSG::SOLIC_ENTRAR_MUSEO_PERSONA:
msg.msg.osemp.idOrigen = brokerMsg.id;
break;
case MuseoMSG::SOLIC_ENTRAR_MUSEO_INVESTIGADOR:
msg.msg.osemi.idOrigen = brokerMsg.id;
msg.msg.osemi.pertenencias = brokerMsg.msg.param_a;
break;
case MuseoMSG::SOLIC_SALIR_MUSEO_PERSONA:
msg.msg.ossmp.idOrigen = brokerMsg.id;
break;
case MuseoMSG::SOLIC_SALIR_MUSEO_INVESTIGADOR:
msg.msg.ossmi.idOrigen = brokerMsg.id;
msg.msg.ossmi.numeroLocker = brokerMsg.msg.param_a;
break;
case MuseoMSG::NOTIFICAR_CIERRE_MUSEO:
case MuseoMSG::INDICAR_MUSEO_NO_LLENO:
break;
default:
LOG_IPCL("Se recibió operación inválida: %d.",
brokerMsg.msg.op);
continue;
//.........这里部分代码省略.........
示例14: _handleWidgetSignal
/**
* Handles all gtk widget signals by passing them off to a SignalHandler.
*
* @param widget the widget to handle the signal for.
* @param userData the user data pointer to the SignalHandler to use.
*/
static void _handleWidgetSignal(GtkWidget* widget, gpointer userData)
{
SignalHandler* h = static_cast<SignalHandler*>(userData);
h->handleWidgetSignal(widget);
}
示例15: _handleWidgetEvent
/**
* Handles all gtk widget events by passing them off to a SignalHandler.
*
* @param widget the widget to handle the event for.
* @param event the event to handle.
* @param userData the user data pointer to the SignalHandler to use.
*/
static gboolean _handleWidgetEvent(
GtkWidget* widget, GdkEvent* event, gpointer userData)
{
SignalHandler* h = static_cast<SignalHandler*>(userData);
return h->handleWidgetEvent(widget, event) ? TRUE : FALSE;
}