/* * Ivy, C interface * * Copyright (C) 1997-1999 * Centre d'Études de la Navigation Aérienne * * Main loop based on GLUT ( OpenGL ) Toolkit * * Authors: François-Régis Colin * Stéphane Chatty * * $Id$ * * Please refer to file version.h for the * copyright notice regarding this software */ #ifdef WIN32 #include #endif #include #include #include #include #include #ifdef WIN32 #else #include #include #include #include #include #include #include #include #endif #include #include "ivydebug.h" #include "ivychannel.h" #include "ivyglutloop.h" struct _channel { GLUTInputId id_read; GLUTInputId id_delete; void *data; ChannelHandleDelete handle_delete; ChannelHandleRead handle_read; }; static int channel_initialized = 0; void IvyChannelInit(void) { if ( channel_initialized ) return; /* pour eviter les plantages quand les autres applis font core-dump */ #ifndef WIN32 signal( SIGPIPE, SIG_IGN); #endif channel_initialized = 1; } void IvyChannelRemove( Channel channel ) { if ( channel->handle_delete ) (*channel->handle_delete)( channel->data ); glutRemoveInput( channel->id_read ); glutRemoveInput( channel->id_delete ); } static void IvyGlutHandleChannelRead( int source, GLUTInputId id, void *data ) { Channel channel = (Channel)data; TRACE("Handle Channel read %d\n",source ); (*channel->handle_read)(channel,source,channel->data); } static void IvyGlutHandleChannelDelete( int source, GLUTInputId id, void *data ) { Channel channel = (Channel)data; TRACE("Handle Channel delete %d\n",source ); (*channel->handle_delete)(channel->data); } Channel IvyChannelAdd(HANDLE fd, void *data, ChannelHandleDelete handle_delete, ChannelHandleRead handle_read ) { Channel channel; channel = (Channel)malloc( sizeof(struct _channel) ); if ( !channel ) { fprintf(stderr,"NOK Memory Alloc Error\n"); exit(0); } channel->handle_delete = handle_delete; channel->handle_read = handle_read; channel->data = data; channel->id_read = glutAddInput( fd, IvyGlutHandleChannelRead, channel); channel->id_delete = glutAddInput( fd, IvyGlutHandleChannelDelete, channel); return channel; } void IvyChannelStop () { /* To be implemented */ }