Exemplo n.º 1
0
void Win32Socket::set_handle(SOCKET new_handle, bool new_close_handle)
{
	close_handles();
	handle = new_handle;
	close_handle = new_close_handle;
	create_event_handles();
	select_events();
}
Exemplo n.º 2
0
void *cursor_motion_thread(void *targs) {

    struct MCursor *this = (struct MCursor *)targs;
 
    Display *dpy;
    int xi_opcode, event, error;
    XEvent ev;

    dpy = XOpenDisplay(NULL);

    if (!dpy) {
    	MLOGE("Failed to open display.\n");
    	return (void *)-1;
    }

    if (!XQueryExtension(dpy, "XInputExtension", &xi_opcode, &event, &error)) {
       MLOGE("X Input extension not available.\n");
       XCloseDisplay(dpy);
       return (void *)-1;
    }

    if (!has_xi2(dpy)){
        XCloseDisplay(dpy);
        return (void *)-1;
    }
       

    /* select for XI2 events */
    select_events(dpy, DefaultRootWindow(dpy));

    while(1) 
    {
    	XGenericEventCookie *cookie = &ev.xcookie;
    	Window      	root_ret, child_ret;
    	int         	root_x, root_y;
    	int         	win_x, win_y;
    	unsigned int    mask;

    	XNextEvent(dpy, &ev);

    	if (cookie->type == GenericEvent && cookie->extension == xi_opcode && XGetEventData(dpy, cookie)){
            
            if (cookie->evtype == XI_RawMotion) {
                XQueryPointer(dpy, DefaultRootWindow(dpy), &root_ret, &child_ret, &root_x, &root_y, &win_x, &win_y, &mask);
                update_cursor(dpy, this->mMdpy, &this->mBuffer, root_x, root_y);
            }

            XFreeEventData(dpy, cookie);
        }

    	
    }
 
    XCloseDisplay(dpy);
    return NULL;
}
Exemplo n.º 3
0
Win32Socket::Win32Socket(SOCKET handle)
: handle(handle), close_handle(true), event_handle(0), receive_handle(0), send_handle(0), except_handle(0)
{
	try
	{
		create_event_handles();
		select_events();
	}
	catch (...)
	{
		close_handles();
		throw;
	}
}
Exemplo n.º 4
0
int main (int argc, char **argv)
{
    Display *dpy;
    int xi_opcode, event, error;
    Window win;
    XEvent ev;

    dpy = XOpenDisplay(NULL);

    if (!dpy) {
        fprintf(stderr, "Failed to open display.\n");
        return -1;
    }

    if (!XQueryExtension(dpy, "XInputExtension", &xi_opcode, &event, &error)) {
           printf("X Input extension not available.\n");
              return -1;
    }

    if (!has_xi2(dpy))
        return -1;

    /* Create a simple window */
    win = create_win(dpy);

    /* select for XI2 events */
    select_events(dpy, win);

    while(1) {
        XGenericEventCookie *cookie = &ev.xcookie;

        XNextEvent(dpy, &ev);

        if (cookie->type != GenericEvent ||
            cookie->extension != xi_opcode)
            continue;

        if (XGetEventData(dpy, cookie))
        {
            printf("Event type %d received\n", cookie->evtype);
            XFreeEventData(dpy, &ev.xcookie);
        }
    }

    return 0;
}
Exemplo n.º 5
0
int
main(int argc, char **argv)
{
  unsigned int  mainWndId;
  unsigned int  gc;
  KWEvent       event;
  
  mainWndId = new_main_window_simple(50, 50, WIDTH, HEIGHT, "Window 1, This is the first one.");
  if (mainWndId == BAD_WND_ID) {
    LOG(("%s\n", "<Demo2 Error> can not create the main window."));
    exit (-1);
  }
  
  gc = new_gc();
  
  select_events(mainWndId, EVENT_MASK_EXPOSURE);
  map_window(mainWndId);
  
  for (;;) {
    get_next_event(&event);
    switch (event.type) {
    }
  }
}
Exemplo n.º 6
0
void Win32Socket::create_udp()
{
	create_socket_handle(SOCK_DGRAM);
	create_event_handles();
	select_events();
}
Exemplo n.º 7
0
void Win32Socket::create_tcp()
{
	create_socket_handle(SOCK_STREAM);
	create_event_handles();
	select_events();
}
Exemplo n.º 8
0
/***********************************************************************//**
 * @brief Select event data
 *
 * This method reads in the application parameters and loops over all
 * observations that were found to perform an event selection. Event
 * selection is done by writing each observation to a temporary file and
 * re-opening the temporary file using the cfitsio event filter syntax.
 * The temporary file is deleted after this action so that no disk overflow
 * will occur. 
 ***************************************************************************/
void ctselect::run(void)
{
    // Switch screen logging on in debug mode
    if (logDebug()) {
        log.cout(true);
    }

    // Get parameters
    get_parameters();

    // Write parameters into logger
    if (logTerse()) {
        log_parameters();
        log << std::endl;
    }

    // Write observation(s) into logger
    if (logTerse()) {
        log << std::endl;
        log.header1("Observations before selection");
        log << m_obs << std::endl;
    }

    // Write header
    if (logTerse()) {
        log << std::endl;
        log.header1("Event selection");
    }

    // Initialise counters
    int n_observations = 0;

    // Loop over all observation in the container
    for (int i = 0; i < m_obs.size(); ++i) {

        // Initialise event input and output filenames
        m_infiles.push_back("");

        // Get CTA observation
        GCTAObservation* obs = dynamic_cast<GCTAObservation*>(&m_obs[i]);

        // Continue only if observation is a CTA observation
        if (obs != NULL) {

            // Write header for observation
            if (logTerse()) {
                if (obs->name().length() > 1) {
                    log.header3("Observation "+obs->name());
                }
                else {
                    log.header3("Observation");
                }
            }

            // Increment counter
            n_observations++;

            // Save event file name (for possible saving)
            m_infiles[i] = obs->eventfile();

            // Get temporary file name
            std::string filename = std::tmpnam(NULL);

            // Save observation in temporary file
            obs->save(filename, true);

            // Log saved FITS file
            if (logExplicit()) {
                GFits tmpfile(filename);
                log << std::endl;
                log.header1("FITS file content of temporary file");
                log << tmpfile << std::endl;
                tmpfile.close();
            }

            // Check temporary file
            std::string message = check_infile(filename);
            if (message.length() > 0) {
                throw GException::app_error(G_RUN, message);
            }

            // Load observation from temporary file, including event selection
            select_events(obs, filename);

            // Remove temporary file
            std::remove(filename.c_str());
            
        } // endif: had a CTA observation

    } // endfor: looped over all observations

    // If more than a single observation has been handled then make sure that
    // an XML file will be used for storage
    if (n_observations > 1) {
        m_use_xml = true;
    }

    // Write observation(s) into logger
    if (logTerse()) {
        log << std::endl;
        log.header1("Observations after selection");
        log << m_obs << std::endl;
    }

    // Return
    return;
}