epoc-utilities.hpp

Go to the documentation of this file.
00001 #ifndef __epoc_utilities_hpp__
00002 #define __epoc_utilities_hpp__
00003 
00004 // Utilities that require Symbian-specific includes in the header.
00005 
00006 #include <e32base.h> // CTrapCleanup, CActiveScheduler
00007 
00008 // Successful CTrapCleanup::New(); leads to installation as the
00009 // current cleanup stack. The next cleanup stack on the stack (if any)
00010 // becomes the current one as we delete the current one with
00011 // ~CTrapCleanup().
00012 // 
00013 // Note that we are assuming KErrNoMemory error upon failure, as no
00014 // other information is available.
00015 #define WITH_CLEANUP_STACK(_task) \
00016   { \
00017   CTrapCleanup* cleanup = CTrapCleanup::New(); \
00018   if (!cleanup) return KErrNoMemory; \
00019   { _task ; }           \
00020   delete cleanup; \
00021   }
00022 
00023 // Note that we are assuming KErrNoMemory error upon failure, as no
00024 // other information is available.
00025 #define WITH_ACTIVE_SCHEDULER(_task) \
00026   { \
00027   CActiveScheduler* scheduler = new CActiveScheduler; \
00028   if (!scheduler) return KErrNoMemory; \
00029   CActiveScheduler::Install(scheduler); \
00030   { _task ; }       \
00031   delete scheduler; \
00032   }
00033 
00034 #define WITH_CLEANUP_STACK_ERR(_errCode,_task)  \
00035   { \
00036   CTrapCleanup* _cleanup = CTrapCleanup::New(); \
00037   if (_cleanup) { { _task ; } delete _cleanup; } \
00038   else { _errCode = KErrNoMemory; } \
00039   }
00040 
00041 #define WITH_ACTIVE_SCHEDULER_ERR(_errCode,_task) \
00042   { \
00043   CActiveScheduler* _scheduler = new CActiveScheduler; \
00044   if (_scheduler) {              \
00045     CActiveScheduler::Install(_scheduler);         \
00046     { _task ; }                \
00047     delete _scheduler;               \
00048   } else {                 \
00049     _errCode = KErrNoMemory;             \
00050   }                  \
00051   }
00052 
00053 // This comes from Forum Nokia, and indeed should be quite safe when
00054 // "op" is a free function of some kind that takes a single void*
00055 // argument.
00056 #define CleanupOpPushL(op,ptr) \
00057   CleanupStack::PushL(TCleanupItem(reinterpret_cast<TCleanupOperation>(op), ptr))
00058 
00059 #endif /* __epoc_utilities_hpp__ */
00060 
00061 /**
00062 
00063 epoc-utilities.hpp
00064 
00065 Copyright 2009 Helsinki Institute for Information Technology (HIIT)
00066 and the authors. All rights reserved.
00067 
00068 Authors: Tero Hasu <tero.hasu@hut.fi>
00069 
00070 Permission is hereby granted, free of charge, to any person
00071 obtaining a copy of this software and associated documentation files
00072 (the "Software"), to deal in the Software without restriction,
00073 including without limitation the rights to use, copy, modify, merge,
00074 publish, distribute, sublicense, and/or sell copies of the Software,
00075 and to permit persons to whom the Software is furnished to do so,
00076 subject to the following conditions:
00077 
00078 The above copyright notice and this permission notice shall be
00079 included in all copies or substantial portions of the Software.
00080 
00081 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00082 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00083 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00084 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
00085 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
00086 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00087 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
00088 SOFTWARE.
00089 
00090  **/

ContextLogger2—ContextLogger2 Logger Daemon Internals—Generated on Mon May 2 13:49:52 2011 by Doxygen 1.6.1