portable.h

Go to the documentation of this file.
00001 #ifndef PORTABILITY_GROUP
00002 #define PORTABILITY_GROUP
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : portability definitions                                           *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *******************************************************************************
00010 * Copyright (c) 1994-$now By Author.  This program is free software; you can  *
00011 * redistribute it and/or modify it under the terms of the GNU General Public  *
00012 * License as published by the Free Software Foundation; either version 2 of   *
00013 * the License or (at your option) any later version.  This is online at:      *
00014 *     http://www.fsf.org/copyleft/gpl.html                                    *
00015 * Please send any updates to: fred@gruntose.com                               *
00016 \*****************************************************************************/
00017 
00018 #include "array.h"
00019 
00021 
00027 // forward.
00028 class char_star_array;
00029 
00030 // gnarly headers that are needed for certain types of compilation...
00031 
00032 #ifdef __UNIX__
00033   #include <unistd.h>
00034 #endif
00035 #ifndef NO_XWINDOWS
00036   #ifdef __XWINDOWS__
00037     #include <Intrinsic.h>
00038     #include <StringDefs.h>
00039     #include <Xm/Xm.h>
00040     #include <Xlib.h>
00041   #endif
00042 #endif
00043 #ifdef __WIN32__
00044   #ifndef STRICT
00045     #define STRICT
00046   #endif
00047   // windows headers...
00048   #ifndef _AFXDLL
00049     // include ms-windows headers only if we're not doing mfc; mfc has its own
00050     // special way of including the headers.
00051     #include <windows.h>
00052   #else
00053     #include <afx.h>
00054     #include <afxwin.h>
00055   #endif
00056   // winsock support...
00057   #undef FD_SETSIZE
00058   #define FD_SETSIZE 1000
00059     // if you don't set this, you can only select on a default of 64 sockets.
00060   #include <winsock2.h>
00061 #endif
00062 
00063 // forward.
00064 struct timeval;
00065 class version;
00066 
00067 // wrapper classes defined in the sequel...
00068 //
00069 //   application_instance -- this program's application object; used mainly
00070 //       in ms-windows.
00071 //
00072 //   window_handle -- a wrapper for the root of all objects that can be
00073 //       referred to in the relevant windowing system.
00074 
00075 #ifdef __UNIX__
00076   // the application_instance class is implemented very simply for unix;
00077   // it's a stand-in since unix apps don't refer to an instance handle like
00078   // ms-windows does.
00079   typedef void *application_instance;
00080 
00081   // some definitions to quiet complaints from win32-based code.
00082   #ifndef LONGINT_SIZE
00083     #if defined(__alpha) || (defined(__HOS_AIX__) && defined(_LP64)) \
00084         || defined(__sparcv9) || defined(__LP64__) 
00085       #define LONGINT_SIZE 8
00086     #else
00087       #define LONGINT_SIZE 4
00088     #endif
00089   #endif
00090   #if (LONGINT_SIZE == 4)
00091     // be compatible with linux's definitions on this subject.
00092     typedef unsigned long DWORD;
00093   #else
00094     typedef unsigned int DWORD;
00095   #endif
00096 
00097   typedef void *HANDLE;
00098 
00099   //temp; these just mimic function prototypes coming from non-portable code.
00100   typedef void *ATOM;
00101   typedef void *BITMAPINFO;
00102   typedef void *HBITMAP;
00103   typedef void *HDC;
00104   typedef void *RGBQUAD;
00105   #define LoadBitmap(a, b) (a)
00106   #define __stdcall 
00107   #define afx_msg
00108 
00109   // portability definitions for the X windowing system.
00110   #ifndef NO_XWINDOWS  // protects regions with similar names.
00111   #ifdef __XWINDOWS__
00112     typedef Widget window_handle;
00114 
00115     typedef Colormap window_colormap;
00117 
00118     typedef XColor window_color;
00120 
00121     typedef XmString window_string;
00123 
00124 //is that really fixed?
00125     const int MAXIMUM_COLOR_INTENSITY = 65535;
00126       // largest valid value a color component (R, G or B) can have.
00127   #else
00128     // no x-windows.
00129     typedef void *window_handle;
00130   #endif
00131   #endif
00132 #endif
00133 
00134 #ifdef __WIN32__
00135   typedef HINSTANCE application_instance;
00136     // our moniker for an application's guts.
00137 
00138   typedef HWND window_handle;
00139     // our alias for window handles in win32.
00140 #endif
00141 
00142 // now the actual portable namespace...
00143 
00144 namespace portable {
00145 
00146   // assorted useful system functions:
00147 
00148   version get_OS_version();
00150 
00153   u_int process_id();
00155 
00156   istring current_directory();
00158 
00159   istring application_name();
00161 
00162   istring module_name(const void *module_handle = NIL);
00164 
00166   u_int system_uptime();
00168 
00169   double rolling_uptime();
00171 
00172   void sleep_ms(u_int msec);
00174 
00178   istring env_string(const istring &variable_name);
00180 
00185   bool set_environ(const istring &variable_name, const istring &value);
00187 
00190   u_int system_error();
00192 
00193   istring system_error_text(u_int error_to_show);
00195 
00197   istring null_device();
00199 
00202   char_star_array break_line(istring &app, const istring &parameters);
00204 
00208   enum process_launch_flags {
00209     HIDE_APP_WINDOW = 0x1,
00211     AWAIT_APP_EXIT = 0x2,
00213     RETURN_IMMEDIATELY = 0x4,
00215     AWAIT_VIA_POLLING = 0x8,
00217     SHELL_EXECUTE = 0x10
00219   };
00220 
00221   u_int launch_process(const istring &app_name, const istring &command_line,
00222           int flag, u_int &child_id);
00224 
00234   timeval fill_timeval_ms(int milliseconds);
00236 
00240   // this only really helps for win32.
00241   extern application_instance _i_handle;
00243   #define DEFINE_INSTANCE_HANDLE application_instance portable::_i_handle = 0
00245 
00247   #define SET_INSTANCE_HANDLE(value) portable::_i_handle = value
00249 
00250   #define GET_INSTANCE_HANDLE() portable::_i_handle
00252 
00254 
00255   // Unix and Linux specific items are included here.
00256   #ifdef __UNIX__
00257     istring get_cmdline_from_proc();
00259 
00260     char *itoa(int to_convert, char *buffer, int radix);
00262 
00268     #define RGB(r, g, b) (b + (g << 8) + (r << 16))
00270   #endif
00271 
00272   // ms-windows of more modern types, i.e. win32.
00273   #ifdef __WIN32__
00274 
00275     bool event_poll(MSG &message);
00277 
00282 //hmmm: is there an equivalent to this for unix?
00283     bool is_address_valid(const void *address, int size_expected,
00284             bool writable = false);
00286 
00290     #define BROADCAST_HANDLE HWND_BROADCAST
00291 
00292     bool has_win95_style_shell();
00294 
00298     enum known_operating_systems { WIN_95, WIN_NT, WIN_2K, WIN_XP, UNKNOWN_OS };
00299     known_operating_systems determine_OS();
00301 
00303     istring rc_string(u_int id, application_instance instance);
00305 
00308     istring rc_string(u_int id);
00310 
00313     void show_wait_cursor();
00315     void show_normal_cursor();
00317 
00318   #endif // win32.
00319 
00320 } // namespace.
00321 
00323 class char_star_array : public array<char *>
00324 {
00325 public:
00326   inline char_star_array() : array<char *>(0, NIL, SIMPLE_COPY | EXPONE
00327       | FLUSH_INVISIBLE) {}
00328   inline ~char_star_array() {
00329     // clean up all the memory we're holding.
00330     for (int i = 0; i < length(); i++) {
00331       delete [] (use(i));
00332     }
00333   }
00334 };
00335 
00336 #endif // outer guard.
00337 

Generated on Sat Aug 30 04:31:42 2008 for HOOPLE Libraries by  doxygen 1.5.1