_tests/fsLog/main.cpp

00001 
00002 //---------------------------------------------------------------------------
00003 #include <fs/sys/fsLog.h>
00004 
00005 #include <fs/sys/fsDll.h>
00006 
00007 #include <cassert>
00008 //---------------------------------------------------------------------------
00009 int main()
00010 {
00011     using namespace fs::sys;
00012 
00013     FS_LOG("o.EXE The application has been launched.");    
00014     FS_LOG("!.EXE Sample warning message!");
00015     FS_LOG("x.EXE Sample error message!");
00016     FS_LOG("o.EXE Still logs only into the log history...");
00017         
00018     static Log_t AppLog(Log_t::LOG_FILE | Log_t::LOG_STDOUT);
00019     ModLog().SetTgt(&AppLog); // link 'module log' => 'app log'
00020     
00021     FS_LOG("o.EXE First routed (real-time) message.");
00022                 
00023     FS_LOG("o.EXE At this point a module is loaded.");
00024     { 
00025         // load a module
00026         fs::sys::Dll_t Dll("fsLogDll.dll");
00027         assert(Dll.IsValid());
00028         
00029         // export a function from the module
00030         typedef void (* Bind_fn)(Log_t *, bool);
00031         Bind_fn pfnBind = static_cast<Bind_fn>(Dll.GetSymb("BindAppLog"));
00032         assert(pfnBind);
00033         
00034         // bind 'Dll (module) Log' => 'AppLog', set 'AppLog' as a target
00035         (*pfnBind)(&AppLog, true);
00036                         
00037         // export a function from the module
00038         typedef int (* SomeDllFunc_fn)(int);
00039         SomeDllFunc_fn pfnSomeDllFunc = static_cast<SomeDllFunc_fn>
00040          (Dll.GetSymb("SomeDllFunc"));
00041         assert(pfnSomeDllFunc);
00042 
00043         // call the function exported from the module        
00044         int nRes = (*pfnSomeDllFunc)(10);
00045         FS_LOG("o.EXE The result of SomeDllFunc(10) is : %d", nRes);
00046         
00047         // unbind 'Dll (module) Log', set no target
00048         (*pfnBind)(&AppLog, false);
00049     }
00050     FS_LOG("o.EXE At this point the module is unloaded.");
00051     
00052     FS_LOG("o.EXE The application is about to be terminated.");
00053            
00054     return 0;
00055 }
00056 //---------------------------------------------------------------------------
00057 // [000000:015] o.EXE The application has been launched.
00058 // [000000:015] !.EXE Sample warning message!
00059 // [000000:015] x.EXE Sample error message!
00060 // [000000:015] o.EXE Still logs only into the log history...
00061 // [000000:015] o.EXE First routed (real-time) message.
00062 // [000000:015] o.EXE At this point a module is loaded.
00063 // [000000:015] o.DLL The module has just been attached.
00064 // [000000:015] o.DLL Still logs only into the log history...
00065 // [000000:015] o.DLL SomeDllFunc(10) has just been called.
00066 // [000000:015] o.EXE The result of SomeDllFunc(10) is : 11
00067 // [000000:015] o.EXE At this point the module is unloaded.
00068 // [000000:015] o.EXE The application is about to be terminated.
00069 // o.LOG 1 warning(s), 1 error(s) found.
00070 //---------------------------------------------------------------------------

FipS' Code (Thu Feb 15 22:43:35 2007) - (c) Filip STOKLAS (FipS) - [ www ] [ Guest Book ]