FX::FXProcess Class Reference

#include <FXProcess.h>

List of all members.


Detailed Description

Provides process-wide information and control.

Where FXApp initialises the GUI subsystem, FXProcess initialises just those parts sufficient for command-line operation. Probably one of its most useful facilities is FXProcess_StaticInit which is used by a number of internal classes already.

FXProcess should be initialised first thing into main():

int main(int argc, char *argv[])
{
    FXProcess myprocess(argc, argv);
    FXApp app("name");      // Only for GUI apps
    app.init(argc, argv);   // Only for GUI apps
    ...
    app.create();           // Only for GUI apps
    ...
    return app.run();       // Only for GUI apps
}

Dynamic library facilities

You should use dllLoad() to load dynamic libraries - this loads and runs any FXProcess_StaticInit's the newly loaded library may have. If you manage your own loading, call runPendingStaticInits(). The search behaviour on POSIX is different than that for dlopen() - if a relative path, it emulates Windows by searching around where the executable is, then the current directory, then dlopen()'s default. It also tries appending .so if one isn't present already as well as prepending lib - this behaviour ensures that equivalent behaviour occurs both on Windows and POSIX. Watch out for calling DLL's the same as executables - on POSIX, there is no .exe extension to differentiate.

Once loaded you can resolve symbols using dllHandle::dllResolve() which returns a functor for that API. Note that C++ mangles its API names so you will have to specify extern "C" before their declaration in your DLL.

Free system resources

hostOSProcessorLoad(), hostOSMemoryLoad() and hostOSDiscIOLoad() allow your code to determine how free the system is in those areas. This can be used to dynamically adjust whether to use lots of memory and a fast algorithm or little memory and a slow algorithm.

A few parts of TnFOX use the convenience functions processorFull(), memoryFull() and discIOFull() but this facility is mostly intended for Tn. These functions return an integer index whereby zero is not full, one is getting full, two is nearly full and three is full and over. These numbers can be included in calculations as divisors of buffer sizes etc.

Note:
hostOSProcessLoad() and hostDiscIOLoad() are currently unimplemented. At some stage I'll do like FXSecure and maintain a shared memory region with the last five seconds of data from which meaningful values can be constructed.

Process-wide thread pool

A process-wide thread pool consisting of four threads is available at FXProcess::threadPool() and is created on first use. FX::QThreadPool offers timed callback facilities which are used by other code such as FX::FXFSMonitor. Once created, the thread pool lasts until the process terminates.

Security:

On POSIX, there is the weird and wonderful world of real and effective user ids and groups. Basically the real id of a process is under which user's shell it is running whereas the effective id is which user the process is impersonating. It gets more complex again on Linux because a process can impersonate someone different again only when accessing the file system. This does not in my mind make for easy security - and worst of all, you can't change these impersonation settings on a per-thread basis, only on a per-process one.

Hence we are substantially limited in what we can do whilst keeping semantics similar between NT and POSIX - unfortunately we need the ability to run as root but act like someone else because the Tn kernel can run as a daemon/service and the secure heap needs to be able to lock memory pages. I've decided that if the filing system is accessed like the real uid and TnFOX's ACL based security support forces the owner on all things it touches to be the real uid, it's safe to run the process with the suid bit set (ie; acting like root). Of course, users may not agree with this :)

Note:
userHandedness() is currently only implemented for Windows

Definition at line 134 of file FXProcess.h.

Public Types

typedef QValueList< MappedFileInfoMappedFileInfoList
typedef Generic::Functor<
Generic::TL::create< void,
bool >::value > 
FatalExitUpcallSpec
 UNKNOWN_HANDED
 LEFT_HANDED
 RIGHT_HANDED
enum  UserHandedness { UNKNOWN_HANDED, LEFT_HANDED, RIGHT_HANDED }

Public Member Functions

 FXProcess ()
 FXProcess (int &argc, char *argv[])
 ~FXProcess ()
bool runPendingStaticInits (int &argc, char *argv[], FXStream &txtout)

Static Public Member Functions

static void exit (FXint code=0)
static bool isAutomatedTest () throw ()
static FXProcessinstance ()
static FXuint getMsCount ()
static void getTimeOfDay (struct timeval *ts)
static FXulong getNsCount ()
static FXuint id ()
static FXuint noOfProcessors ()
static FXuint pageSize ()
static MappedFileInfoList mappedFiles (bool forceRefresh=false)
static const FXStringexecpath ()
static FXString dllPath (void *addr, void **dllstart=0, void **dllend=0)
static dllHandle dllLoad (const FXString &path)
static void * dllResolveBase (const dllHandle &h, const char *apiname)
static void dllUnload (dllHandle &h)
static FXString hostOS (FXString *myos=0, FXString *architecture=0)
static FXString hostOSDescription (FXString *myapi=0, FXString *kernelname=0, FXString *kernelversion=0, FXString *apiversion=0, FXString *architecture=0)
static void buildInfo (int *svnrev=0)
static FXfloat hostOSProcessorLoad ()
static FXuint processorFull ()
static FXfloat hostOSMemoryLoad (FXuval *totalPhysMem=0)
static FXuint memoryFull ()
static MemoryUsageInfo processMemoryUsage (FXuint processId=FXProcess::id())
static FXfloat hostOSDiscIOLoad (const FXString &path)
static FXfloat hostOSDiskIOLoad (const FXString &path)
static FXuint discIOFull (const FXString &path)
static FXuint diskIOFull (const FXString &path)
static void overrideFreeResources (FXfloat memory=-1, FXfloat processor=-1, FXfloat discio=-1)
static FXuval virtualAddrSpaceLeft (FXuval chunk=1)
static QValueList< MountablePartitionmountablePartitions ()
static void mountPartition (const FXString &partitionName, const FXString &location=FXString::nullStr(), const FXString &fstype=FXString::nullStr(), bool readWrite=true)
static void unmountPartition (const FXString &location)
static QThreadPoolthreadPool ()
static UserHandedness userHandedness ()
static void overrideUserHandedness (UserHandedness val)
static FXuint screenScale (FXuint value)
static void overrideScreenScale (FXuint percent)
static void overrideScreenSize (FXint w, FXint h)
static void addFatalExitUpcall (FatalExitUpcallSpec upcallv)
static bool removeFatalExitUpcall (FatalExitUpcallSpec upcallv)
static QMemArray< void * > lockedPages ()
static void int_addStaticInit (FXProcess_StaticInitBase *o)
static void int_removeStaticInit (FXProcess_StaticInitBase *o)
static void int_addStaticDepend (FXProcess_StaticDepend *d)

Friends

class FXProcess_MemLock
class FXWindow
class FXShell

Classes

class  dllHandle
struct  MappedFileInfo
 A structure containing information about a mapped file. More...
struct  MemoryUsageInfo
 Holds information about a process' memory usage. More...
struct  MountablePartition
 Information about a mountable partition. More...


The documentation for this class was generated from the following file:
(C) 2002-2009 Niall Douglas. Some parts (C) to assorted authors.
Generated on Fri Nov 20 18:35:40 2009 for TnFOX by doxygen v1.4.7