00001 /* Seventh VOS tutorial. Creating your own MetaObjects 00002 00003 This tutorial covers: 00004 - Using our Hello metaobject 00005 - The VOS logging facility 00006 00007 This file (vostut7server.cc) is released into the public domain. No 00008 restrictions are placed on its use, distribution or inclusion into 00009 other works. 00010 */ 00011 00012 // Bring in the definitions of various "Hello" metaobject classes. 00013 #include "vostut7hello.hh" 00014 00015 int main(int, char**) 00016 { 00017 cout << "VOS Tutorial 7 Server\n\n"; 00018 00019 Hello::registerExtenders(); 00020 00021 LocalSocketSite site(&NoAccessControl::static_); 00022 site.setTimeoutOnSelect(-1); 00023 00024 00025 /* The preferred way to write out logging messages for debugging 00026 and user notification is to use the VOS logging facility. This 00027 facility allows for many separate logging channels which can be 00028 individually adjusted to be more or less verbose. The way this 00029 works is simple: each log message consists of the log channel, 00030 the log level, and the message itself. The log level of the 00031 statement is compared against the channel log level, and if the 00032 statement level is equal to or lower than the current level it 00033 is printed out. The log levels run from 0 to 5, where level 0 00034 is reserved for only the absolutely most important messages and 00035 5 is used for debugging that will quickly spam your display 00036 with junk. The default level is 2. Debugging statements 00037 should generally be at level 3 or 4. 00038 00039 Note that if the message doesn't have a good enough log level, 00040 the actual output (eg foo << bar << baz) will never be never 00041 executed, so disabled logging statement are efficiently 00042 overlooked. 00043 */ 00044 LOG("helloserver", 1, "started server at " << site.getURL().getString()); 00045 00046 00047 vRef<MetaObject> mobj = site.createMetaObject("hello", typeid(Hello).name(), 0); 00048 00049 00050 // Extract the "Hello" interface 00051 00052 Hello& h = MetaObject::meta_cast<Hello&>(*mobj); 00053 00054 00055 // Now call the hello() method (same as in the client!) 00056 00057 string s = h.hello("I feel like I'm talking to myself."); 00058 00059 00060 LOG("helloserver", 1, "Called hello locally and got this back: '" << s << "'"); 00061 00062 while(true) { 00063 site.flushIncomingBuffers(); 00064 } 00065 } 00066