evq_event.c

Go to the documentation of this file.
00001 #include "common/evq_event.h"
00002 
00003 #include "common/assertions.h"
00004 
00005 #include <stdlib.h>
00006 
00007 // --------------------------------------------------------------------------------
00008 // for POSIX...
00009 
00010 #ifndef __EPOC32__
00011 
00012 void event_init(EventQueue* queue)
00013 {
00014   queue_init(queue);
00015 }
00016 
00017 #if EVENT_CALLBACK_WITH_GERROR
00018 gboolean event_loop(EventQueue* queue, GError** error)
00019 {
00020   Event* event;
00021   for (;;) {
00022     event = (Event*)queue_get(queue);
00023     if (!event)
00024       break;
00025     if (!((event->callback)(event, error))) {
00026       return FALSE;
00027     }
00028   }
00029   return TRUE;
00030 }
00031 #else
00032 void event_loop(EventQueue* queue)
00033 {
00034   Event* event;
00035   for (;;) {
00036     event = (Event*)queue_get(queue);
00037     if (!event)
00038       break;
00039     (event->callback)(event);
00040   }
00041 }
00042 #endif
00043 
00044 void event_put(EventQueue* queue, Event* event)
00045 {
00046   queue_put((Queue*)queue, (QueueItem*)event);
00047 }
00048 
00049 void event_remove(EventQueue* queue, Event* event)
00050 {
00051   queue_remove((Queue*)queue, (QueueItem*)event);
00052 }
00053 
00054 void event_loop_stop(EventQueue* queue)
00055 {
00056   queue_stop(queue);
00057 }
00058 
00059 void event_close(EventQueue* queue)
00060 {
00061   queue_close(queue);
00062 }
00063 
00064 #endif
00065 
00066 // --------------------------------------------------------------------------------
00067 // for Symbian...
00068 
00069 #ifdef __EPOC32__
00070 
00071 #include "common/epoc-event-internal.h"
00072 
00073 void event_init(EventQueue* dummy)
00074 {
00075 }
00076 
00077 // Processes events until requested otherwise. On POSIX, this runs the
00078 // event queue. On Symbian, this creates a nested scheduling loop in
00079 // the current active scheduler, using a CActiveSchedulerWait to
00080 // control the loop; this call essentially invokes
00081 // CActiveSchedulerWait::Start.
00082 MAYBE_ERROR_RTYPE event_loop(EventQueue* queue MAYBE_ERROR_PARAM)
00083 {
00084   assert(queue && "event queue may not be NULL when using nested loops");
00085 
00086 #if EVENT_CALLBACK_WITH_GERROR
00087   assert_error_unset(error);
00088 
00089   // Use a scheduler that records errors to our error argument as appropriate.
00090   if (error)
00091     // Here the error argument is for the scheduler to use, not for
00092     // this function to report an error.
00093     event_scheduler_replace(error);
00094 #endif
00095 
00096   if (!queue->aoLoop) {
00097     AoLoop* loop = AoLoop_new();
00098     if (!loop)
00099       abort();
00100     queue->aoLoop = loop;
00101   }
00102 
00103   AoLoop_start(queue->aoLoop);
00104 
00105 #if EVENT_CALLBACK_WITH_GERROR
00106   // Note that here we exceptionally ignore errors if "error" was
00107   // passed as NULL. That is, we never return FALSE in such a case.
00108   // 
00109   // We cannot distinguish between a NULL GError and no GError here,
00110   // which is a design limitation.
00111   return !(error && *error);
00112 #endif
00113 }
00114 
00115 // Stops the event loop. On POSIX, this simply stops running the event
00116 // queue. On Symbian, this essentially invokes
00117 // CActiveSchedulerWait::AsyncStop.
00118 void event_loop_stop(EventQueue* queue)
00119 {
00120   assert(queue && "event queue may not be NULL when using nested loops");
00121   assert(queue->aoLoop && "not looping");
00122   AoLoop_stop(queue->aoLoop);
00123 }
00124 
00125 // Frees up any resources associated with an event queue.
00126 void event_close(EventQueue* queue)
00127 {
00128   if (queue && queue->aoLoop) {
00129     AoLoop_delete(queue->aoLoop);
00130     queue->aoLoop = NULL;
00131   }
00132 }
00133 
00134 #endif
00135 
00136 // --------------------------------------------------------------------------------
00137 // common...
00138 
00139 // On Symbian, installs a (new) active scheduler for the calling
00140 // thread. This is essentially a call to CActiveScheduler::Install.
00141 void event_scheduler_install(MAYBE_ERROR_SOLE_PARAM)
00142 {
00143 #ifdef __EPOC32__
00144   if (AoScheduler_install(MAYBE_ERROR_SOLE_ARG))
00145     abort(); // out of memory
00146 #endif
00147 }
00148 
00149 // On Symbian, uninstalls and deletes (the current) active scheduler
00150 // of the calling thread.
00151 void event_scheduler_uninstall()
00152 {
00153 #ifdef __EPOC32__
00154   AoScheduler_uninstall();
00155 #endif
00156 }
00157 
00158 void event_scheduler_replace(MAYBE_ERROR_SOLE_PARAM)
00159 {
00160 #ifdef __EPOC32__
00161   if (AoScheduler_replace(MAYBE_ERROR_SOLE_ARG))
00162     abort(); // out of memory
00163 #endif
00164 }
00165 
00166 /**
00167 
00168 evq_event.c
00169 
00170 Copyright 2009 Helsinki Institute for Information Technology (HIIT)
00171 and the authors. All rights reserved.
00172 
00173 Authors: Tero Hasu <tero.hasu@hut.fi>
00174 
00175 Permission is hereby granted, free of charge, to any person
00176 obtaining a copy of this software and associated documentation files
00177 (the "Software"), to deal in the Software without restriction,
00178 including without limitation the rights to use, copy, modify, merge,
00179 publish, distribute, sublicense, and/or sell copies of the Software,
00180 and to permit persons to whom the Software is furnished to do so,
00181 subject to the following conditions:
00182 
00183 The above copyright notice and this permission notice shall be
00184 included in all copies or substantial portions of the Software.
00185 
00186 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00187 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00188 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00189 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
00190 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
00191 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00192 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
00193 SOFTWARE.
00194 
00195  **/

ContextLogger2—ContextLogger2 Logger Daemon Internals—Generated on Mon May 2 13:49:52 2011 by Doxygen 1.6.1