Example #1
0
void
gui_main::run()
{
 	MSG message;

	// Create a message queue and hook thread messages (we can't just check for them in the loop
	// below, because Windows runs modal message loops e.g. when resizing a window)
	SetWindowsHookEx(WH_GETMESSAGE, &gui_main::threadMessage, NULL, GetCurrentThreadId());
	PeekMessage(&message, NULL, WM_USER, WM_USER, PM_NOREMOVE);

	// Tell the initializing thread
	{
		lock L(init_lock);
		gui_thread = GetCurrentThreadId();
		initialized.notify_all();
	}

	timeBeginPeriod(TIMER_RESOLUTION);
	atexit( end_period );

	poll();

	// Enter the message loop; runs about 60 times per second
	while (GetMessage(&message, 0, 0, 0) > 0) {
		TranslateMessage( &message);
		DispatchMessage( &message);
	}

	// We normally exit the message queue because PostQuitMessage() has been called
	VPYTHON_NOTE( "WM_QUIT (or message queue error) received");
	on_shutdown(); // Tries to kill Python
}
Example #2
0
// ---------------------------------------------------------------------------
void X11WindowImpl::destroy()
{
  if (xwindow != 0) 
  {
    on_shutdown();
    XDestroyWindow(factory->xdisplay, xwindow);
    factory->flushX();
  }
}
void TestPeerLogicAsyncServer::on_write (error_code const& ec, std::size_t bytes_transferred)
{
    if (aborted (ec) || failure (error (ec)))
        return finished ();

    if (unexpected (bytes_transferred == 7, error ()))
        return finished ();

    if (socket ().needs_handshake ())
    {
        socket ().async_shutdown (boost::bind (&TestPeerLogicAsyncServer::on_shutdown, this,
            boost::asio::placeholders::error));
    }
    else
    {
        // on_shutdown will call finished ()
        // we need another instance of ec so we can call on_shutdown()
        error_code ec;
        on_shutdown (socket ().shutdown (Socket::shutdown_both, ec));
    }
}
void TestPeerLogicAsyncClient::on_read_final (error_code const& ec, std::size_t)
{
    if (aborted (ec))
        return finished ();

    // An eof is the normal case. The server should have closed shop.
    //
    if (ec == boost::asio::error::eof)
    {
        if (socket ().needs_handshake ())
        {
            socket ().async_shutdown (boost::bind (&TestPeerLogicAsyncClient::on_shutdown, this,
                boost::asio::placeholders::error));
        }
        else
        {
            // on_shutdown will call finished ()
            error_code ec;
            on_shutdown (socket ().shutdown (Socket::shutdown_send, ec));
        }
    }
    else
    {
        // If we don't get eof, then there should be some other
        // error in there. We don't expect the server to send more bytes!
        //
        // This statement will do the following:
        //
        // error (ec)     save ec into our error state
        // success ()     return true if ec represents success
        // unexpected ()  changes error() to 'unexpected' result if
        //                success() returned true
        //
        unexpected (success (error (ec)), error ());

        return finished ();
    }
}
int main(int argc, char *argv[])
#endif
{

	std::cout << "------------------- REDIS PLUGIN SERVER EXAMPLE -------------------" << std::endl;

	std::string port_str = granada::util::application::GetProperty("port");
	if (port_str.empty()){
		port_str = "80";
	}
	utility::string_t port = utility::conversions::to_string_t(port_str);

	std::string address_str = granada::util::application::GetProperty("address");
	if (address_str.empty()){
		address_str = "http://localhost:";
	}
	else{
		address_str += ":";
	}

	utility::string_t address = utility::conversions::to_string_t(address_str);
	address.append(port);

	on_initialize(address);

	std::cout << "------------------------------------------------\nPress ENTER to terminate server." << std::endl;

	std::string line;
	std::getline(std::cin, line);

	on_shutdown();

	std::cout << "bye,bye.\n\n";

  return 0;
}
Example #6
0
 void
 device::epilogue()
 {
     on_shutdown();
 }
Example #7
0
	void free( T callback ) { on_next_frame().connect( callback ); on_shutdown().disconnect( callback ); }
Example #8
0
	void connect( T callback ) { on_shutdown().connect( callback ); }
Example #9
0
int main(int argc, char *argv[]) {
        int r;
        DBusError error;
        Context c;

        dbus_error_init(&error);

        zero(c);
#ifdef HAVE_AUDIT
        c.audit_fd = -1;
#endif

        if (getppid() != 1) {
                log_error("This program should be invoked by init only.");
                return EXIT_FAILURE;
        }

        if (argc != 2) {
                log_error("This program requires one argument.");
                return EXIT_FAILURE;
        }

        log_set_target(LOG_TARGET_SYSLOG_OR_KMSG);
        log_parse_environment();
        log_open();

#ifdef HAVE_AUDIT
        if ((c.audit_fd = audit_open()) < 0)
                log_error("Failed to connect to audit log: %m");
#endif

        if (bus_connect(DBUS_BUS_SYSTEM, &c.bus, NULL, &error) < 0) {
                log_error("Failed to get D-Bus connection: %s", bus_error_message(&error));
                r = -EIO;
                goto finish;
        }

        log_debug("systemd-update-utmp running as pid %lu", (unsigned long) getpid());

        if (streq(argv[1], "reboot"))
                r = on_reboot(&c);
        else if (streq(argv[1], "shutdown"))
                r = on_shutdown(&c);
        else if (streq(argv[1], "runlevel"))
                r = on_runlevel(&c);
        else {
                log_error("Unknown command %s", argv[1]);
                r = -EINVAL;
        }

        log_debug("systemd-update-utmp stopped as pid %lu", (unsigned long) getpid());

finish:
#ifdef HAVE_AUDIT
        if (c.audit_fd >= 0)
                audit_close(c.audit_fd);
#endif

        if (c.bus) {
                dbus_connection_flush(c.bus);
                dbus_connection_close(c.bus);
                dbus_connection_unref(c.bus);
        }

        dbus_error_free(&error);
        dbus_shutdown();

        return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}