00001 /* 00002 !concept {:name => "A generic AO that completes immediately"} 00003 */ 00004 00005 #include "ut_immediate_epoc.hpp" 00006 #include "ut_immediate.h" 00007 00008 #include "er_errors.h" 00009 00010 // -------------------------------------------------- 00011 // active object 00012 // -------------------------------------------------- 00013 00014 TInt MImmediateObserver::HandleImmediateError(TInt errCode) 00015 { 00016 er_log_symbian(er_FATAL, errCode, "unexpected error in CImmediateAo"); 00017 return errCode; // not reached 00018 } 00019 00020 TInt MImmediateObserver::HandleImmediateLeave(TInt errCode) 00021 { 00022 er_log_symbian(er_FATAL, errCode, "leave in CImmediateAo::RunL()"); 00023 return errCode; // not reached 00024 } 00025 00026 CImmediateAo *CImmediateAo::NewL(MImmediateObserver& aClient) 00027 { 00028 CImmediateAo *object = new (ELeave) CImmediateAo(aClient); 00029 /* 00030 CleanupStack::PushL(object); 00031 object->ConstructL(); 00032 CleanupStack::Pop(); 00033 */ 00034 return object; 00035 } 00036 00037 CImmediateAo::~CImmediateAo() 00038 { 00039 Cancel(); 00040 } 00041 00042 CImmediateAo::CImmediateAo(MImmediateObserver& aObserver) : 00043 CActive(EPriorityStandard), iObserver(aObserver) 00044 { 00045 CActiveScheduler::Add(this); 00046 } 00047 00048 void CImmediateAo::Complete() 00049 { 00050 Cancel(); 00051 00052 iStatus = KRequestPending; 00053 SetActive(); 00054 00055 TRequestStatus* status = &iStatus; 00056 User::RequestComplete(status, KErrNone); 00057 } 00058 00059 void CImmediateAo::DoCancel() 00060 { 00061 if (iStatus == KRequestPending) 00062 { 00063 assert(0 && "CImmediateAo::DoCancel() unexpectedly called"); 00064 } 00065 } 00066 00067 TInt CImmediateAo::RunError(TInt aError) 00068 { 00069 return iObserver.HandleImmediateLeave(aError); 00070 } 00071 00072 void CImmediateAo::RunL() 00073 { 00074 TInt errCode = iStatus.Int(); 00075 if (G_UNLIKELY(errCode)) 00076 iObserver.HandleImmediateError(errCode); 00077 else 00078 iObserver.HandleImmediateEvent(); 00079 } 00080 00081 // -------------------------------------------------- 00082 // opaque object 00083 // -------------------------------------------------- 00084 00085 #define make_error(_errCode, _msg) \ 00086 gx_error_new(domain_symbian, _errCode, _msg ": %s (%d)", \ 00087 plat_error_strerror(_errCode), _errCode) 00088 00089 struct _ut_Immediate : public MImmediateObserver 00090 { 00091 CImmediateAo* ao; 00092 void* userdata; 00093 ut_ImmediateCallback* cb; 00094 00095 virtual void HandleImmediateEvent() 00096 { 00097 (*cb)(userdata, NULL); 00098 } 00099 00100 virtual TInt HandleImmediateError(TInt errCode) 00101 { 00102 (*cb)(userdata, make_error(errCode, "immediate error")); 00103 return 0; 00104 } 00105 }; 00106 00107 // -------------------------------------------------- 00108 // API 00109 // -------------------------------------------------- 00110 00111 extern "C" ut_Immediate* ut_Immediate_new(void* userdata, ut_ImmediateCallback* cb, 00112 GError** error) 00113 { 00114 ut_Immediate* self = g_try_new0(ut_Immediate, 1); 00115 if (G_UNLIKELY(!self)) { 00116 if (error) *error = gx_error_no_memory; 00117 return NULL; 00118 } 00119 self->userdata = userdata; 00120 self->cb = cb; 00121 00122 TRAPD(errCode, self->ao = CImmediateAo::NewL(*self)); 00123 if (G_UNLIKELY(errCode)) { 00124 g_free(self); 00125 if (error) 00126 *error = make_error(errCode, "failed to create native immediate instance"); 00127 return NULL; 00128 } 00129 00130 return self; 00131 } 00132 00133 extern "C" void ut_Immediate_destroy(ut_Immediate* self) 00134 { 00135 if (self) { 00136 delete self->ao; 00137 g_free(self); 00138 } 00139 } 00140 00141 extern "C" gboolean ut_Immediate_complete(ut_Immediate* self, GError** error) 00142 { 00143 (void)error; 00144 ut_Immediate_cancel(self); 00145 self->ao->Complete(); 00146 return TRUE; 00147 } 00148 00149 extern "C" void ut_Immediate_cancel(ut_Immediate* self) 00150 { 00151 self->ao->Cancel(); 00152 } 00153 00154 extern "C" gboolean ut_Immediate_is_active(ut_Immediate* self) 00155 { 00156 return self->ao->IsActive(); 00157 } 00158 00159 /** 00160 00161 ut_immediate_epoc.cpp 00162 00163 Copyright 2009-2010 Helsinki Institute for Information Technology 00164 (HIIT) and the authors. All rights reserved. 00165 00166 Authors: Tero Hasu <tero.hasu@hut.fi> 00167 00168 Permission is hereby granted, free of charge, to any person 00169 obtaining a copy of this software and associated documentation files 00170 (the "Software"), to deal in the Software without restriction, 00171 including without limitation the rights to use, copy, modify, merge, 00172 publish, distribute, sublicense, and/or sell copies of the Software, 00173 and to permit persons to whom the Software is furnished to do so, 00174 subject to the following conditions: 00175 00176 The above copyright notice and this permission notice shall be 00177 included in all copies or substantial portions of the Software. 00178 00179 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00180 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00181 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00182 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 00183 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 00184 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 00185 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 00186 SOFTWARE. 00187 00188 **/
ContextLogger2—ContextLogger2 Logger Daemon Internals—Generated on Mon May 2 13:49:57 2011 by Doxygen 1.6.1