|
Main Page
Class Hierarchy
Alphabetical List
Compound List
File List
Compound Members
|
00001 /********************************************************************************
00002 * *
00003 * Unix Daemon application object *
00004 * *
00005 *********************************************************************************
00006 * Copyright (C) 2003 by Mathew Robertson. All Rights Reserved. *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or *
00009 * modify it under the terms of the GNU Lesser General Public *
00010 * License as published by the Free Software Foundation; either *
00011 * version 2.1 of the License, or (at your option) any later version. *
00012 * *
00013 * This library is distributed in the hope that it will be useful, *
00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
00016 * Lesser General Public License for more details. *
00017 * *
00018 * You should have received a copy of the GNU Lesser General Public *
00019 * License along with this library; if not, write to the Free Software *
00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
00021 *********************************************************************************/
00022 #ifndef WIN32
00023 #ifndef FXDAEMONAPP_H
00024 #define FXDAEMONAPP_H
00025
00026 #ifndef FXOBJECT_H
00027 #include <fox/FXObject.h>
00028 using namespace FX;
00029 #endif
00030 namespace FXEX {
00031 struct FXSysVMessage;
00032
00033 /**
00034 * Main daemon application object, used for when there is no X display to connect to. Works
00035 * in a similar way to FXApp, but with support for System V IPC messages.
00036 */
00037 class FXAPI FXDaemonApp : public FXObject {
00038 FXDECLARE(FXDaemonApp)
00039
00040 private:
00041 // Platform independent private data
00042 FXRegistry registry; // Application setting registry
00043 FXTimer *timers; // List of timers, sorted by time
00044 FXChore *chores; // List of chores
00045 FXTimer *timerrecs; // List of recycled timer records
00046 FXChore *chorerecs; // List of recycled chore records
00047 FXInvocation *invocation; // Modal loop invocation
00048 FXSignal *signals; // Array of signal records
00049 FXint nsignals; // Number of signals
00050 FXInput *inputs; // Input file descriptors being watched
00051 FXint ninputs; // Number of inputs
00052 FXint maxinput; // Maximum input number
00053 void *r_fds; // Set of file descriptors for read
00054 void *w_fds; // Set of file descriptors for write
00055 void *e_fds; // Set of file descriptors for exceptions
00056 FXbool initialized; // Has been initialized
00057 FXSysVMessage *sysVmessages; // List of SysV message queues
00058
00059 private:
00060 static FXDaemonApp *app; // Application pointer
00061
00062 public:
00063 static const FXuchar version[3]; // Version number
00064 static const FXuchar copyright[80]; // Copyright notice
00065 static const FXint MAXSIGNALS; // the maximum number of signals this OS supports
00066
00067 private:
00068 // Internal helper functions
00069 FXDaemonApp(const FXDaemonApp&);
00070 FXDaemonApp &operator=(const FXDaemonApp&);
00071 static void signalhandler(int sig);
00072
00073 protected:
00074 /// Return TRUE when new raw event is available
00075 virtual FXbool getNextEvent(FXRawEvent& ev,FXbool blocking=TRUE);
00076
00077 /// Dispatch raw event
00078 virtual FXbool dispatchEvent(FXRawEvent& ev);
00079
00080 public:
00081 // Messages applications understand
00082 enum {
00083 ID_QUIT=0,
00084 ID_DUMP,
00085 ID_LAST
00086 };
00087
00088 public:
00089 // Message handlers
00090 long onCmdQuit(FXObject*,FXSelector,void*);
00091 long onCmdDump(FXObject*,FXSelector,void*);
00092
00093 public:
00094 /**
00095 * Construct application object; the name and vendor strings are used
00096 * as keys into the registry database for this application's settings
00097 */
00098 FXDaemonApp(const FXString &name="Application",const FXString& vendor="FoxDefault");
00099
00100 /// Get application name
00101 FXString getAppName() const { return registry.getAppKey(); }
00102
00103 /// Get vendor name
00104 FXString getVendorName() const { return registry.getVendorKey(); }
00105
00106 /// Add timeout message to be sent to target object in ms milliseconds
00107 FXTimer* addTimeout(FXint ms,FXObject* tgt,FXSelector sel);
00108
00109 /// Remove timeout, returns NULL
00110 FXTimer* removeTimeout(FXTimer *t);
00111
00112 /**
00113 * Add a idle processing message to be sent to target object when
00114 * the system becomes idle, i.e. there are no events to be processed.
00115 */
00116 FXChore* addChore(FXObject* tgt,FXSelector sel);
00117
00118 /// Remove idle processing message
00119 FXChore* removeChore(FXChore *c);
00120
00121 /**
00122 * Add signal processing message to be sent to target object when
00123 * the signal sig is raised; flags are to be set as per POSIX definitions.
00124 * When immediate is TRUE, the message will be sent to the target right away;
00125 * this should be used with extreme care as the application is interrupted
00126 * at an unknown point it its execution.
00127 */
00128 void addSignal(FXint sig,FXObject* tgt,FXSelector sel,FXuint flags=0);
00129
00130 /// Remove signal message for signal sig
00131 void removeSignal(FXint sig);
00132
00133 /**
00134 * Add a file descriptor fd to be watched for activity as determined
00135 * by mode (an OR of INPUT_READ, INPUT_WRITE, and INPUT_EXCEPT).
00136 * The message will be sent to the target when the specified activity
00137 * is detected on the file descriptor.
00138 */
00139 FXbool addInput(FXInputHandle fd,FXuint mode,FXObject *tgt,FXSelector sel);
00140
00141 /**
00142 * Remove input message and target object for the specified file
00143 * descriptor and mode.
00144 */
00145 FXbool removeInput(FXInputHandle fd,FXuint mode);
00146
00147 /**
00148 * Add a System V message queue input (receive) to be watched for activity
00149 * The message will be sent to the target when the specified message queue
00150 * (and optional data type) is detected on the queue.
00151 * Note: the message type of zero specifies all message types associated
00152 * with that message queue, should be watched
00153 */
00154 FXSysVMessage* addMessageQueue(FXint messageid, FXint maxMsgSize, FXObject* tgt, FXSelector sel, FXint messagetype=0);
00155
00156 /// Remove the System V message queue from the watch list
00157 FXSysVMessage* removeMessageQueue(FXSysVMessage* que);
00158
00159 /// Create application's windows
00160 virtual void create();
00161
00162 /// Destroy application's windows
00163 virtual void destroy();
00164
00165 /// Detach application's windows
00166 virtual void detach();
00167
00168 /// Peek to determine if there's an event
00169 FXbool peekEvent();
00170
00171 /// Perform one event dispatch
00172 void runOneEvent();
00173
00174 /**
00175 * Run the main application event loop until stop() is called,
00176 * and return the exit code passed as argument to stop().
00177 */
00178 FXint run();
00179
00180 /// Run an event loop till some flag becomes non-zero
00181 FXint runUntil(FXuint& condition);
00182
00183 /// Run event loop while there are events are available in the queue
00184 FXint runWhileEvents();
00185
00186 /**
00187 * Terminate the outermost event loop, and all inner modal loops;
00188 * All more deeper nested event loops will be terminated with code equal
00189 * to 0, while the outermost event loop will return code equal to value.
00190 */
00191 void stop(FXint value=0);
00192
00193 /**
00194 * Initialize application.
00195 * Parses and removes common command line arguments,
00196 * opens the display, and reads the registry.
00197 */
00198 void init(int& argc,char** argv);
00199
00200 /**
00201 * Exit application.
00202 * Closes the display and writes the registry.
00203 */
00204 void exit(FXint code=0);
00205
00206 /// Get registry
00207 FXRegistry& reg(){ return registry; }
00208
00209 /// Beep
00210 void beep();
00211
00212 /// Return application instance
00213 static inline FXDaemonApp* instance(){ return app; }
00214
00215 /// Save
00216 virtual void save(FXStream& store) const;
00217
00218 /// Load
00219 virtual void load(FXStream& store);
00220
00221 /// Destroy the application and all reachable resources
00222 virtual ~FXDaemonApp();
00223 };
00224
00225 } // namespace FXEX
00226 #endif // FXDAEMONAPP_H
00227 #endif
00228