epoc-profile-31.cpp

Go to the documentation of this file.
00001 #include "epoc-profile-31.hpp"
00002 
00003 #if __PROFILE_ENABLED__ && __HAVE_PROFILEENGINE_LIB__
00004 
00005 #include "epoc-ao-gerror.hpp"
00006 #include "er_errors.h"
00007 #include "sa_sensor_list_log_db.h"
00008 #include "utils_cl2.h"
00009 
00010 #include "common/assertions.h"
00011 #include "common/error_list.h"
00012 #include "common/logging.h"
00013 #include "common/platform_error.h"
00014 #include "common/utilities.h"
00015 
00016 #include <proengfactory.h> // profileengine.lib
00017 #include <mproengprofile.h>
00018 #include <mproengprofilename.h>
00019 
00020 // The caller must free the returned buffer. The buffer is guaranteed
00021 // to have a zero terminator.
00022 HBufC8* CSensor_profile::GetCurrentProfileNameL()
00023 {
00024   MProEngProfile* profile = iProfileEngine->ActiveProfileLC();
00025 
00026   MProEngProfileName& profileName = profile->ProfileName();
00027   const TDesC& name16 = profileName.Name();
00028 
00029   HBufC8* name8 = ConvToUtf8ZL(name16);
00030 
00031   CleanupStack::PopAndDestroy(); // profile
00032 
00033   return name8;
00034 }
00035 
00036 CSensor_profile* CSensor_profile::NewL(LogDb* aLogDb)
00037 {
00038   CSensor_profile* obj = new (ELeave) CSensor_profile(aLogDb);
00039   CleanupStack::PushL(obj);
00040   obj->ConstructL();
00041   CleanupStack::Pop();
00042   return obj;
00043 }
00044 
00045 CSensor_profile::CSensor_profile(LogDb* aLogDb)
00046 {
00047   iLogDb = aLogDb;
00048 }
00049 
00050 void CSensor_profile::ConstructL()
00051 {
00052   iProfileEngine = ProEngFactory::NewEngineL();
00053   iNotifyHandler = ProEngFactory::NewNotifyHandlerL();
00054 }
00055 
00056 gboolean CSensor_profile::StartL(GError** error)
00057 {
00058   if (!iIsActive) {
00059     iNotifyHandler->RequestProfileActivationNotificationsL(*this);
00060     iIsActive = ETrue;
00061     //log_db_log_status(iLogDb, NULL, "profile sensor started");
00062   }
00063   return TRUE;
00064 }
00065 
00066 void CSensor_profile::Stop()
00067 {
00068   if (iIsActive) {
00069     iNotifyHandler->CancelActiveProfileNotifications();
00070     iIsActive = EFalse;
00071     //log_db_log_status(iLogDb, NULL, "profile sensor stopped");
00072   }
00073 }
00074 
00075 CSensor_profile::~CSensor_profile()
00076 {
00077   delete iNotifyHandler; // surely cancels requests as well
00078   if( iProfileEngine )
00079     {
00080       iProfileEngine->Release();
00081     }
00082 }
00083 
00084 // This implementation never leaves.
00085 void CSensor_profile::HandleProfileActivatedL(TInt aProfileId)
00086 {
00087   // We shall log 'aProfileId'. And we shall also log the current
00088   // profile name, which hopefully still corresponds to the ID. I
00089   // guess in theory it might not, so we might consider using and
00090   // probably caching a 'ProfilesNamesArrayLC' returned value instead.
00091   // xxx
00092   HBufC8* pnDes = NULL;
00093   TRAPD(errCode, pnDes = GetCurrentProfileNameL());
00094   char* profileName;
00095   if (errCode) {
00096     profileName = "";
00097     dblogg("could not get profile name for profile %d: %s (%d)", 
00098      aProfileId, plat_error_strerror(errCode), errCode);
00099   } else {
00100     profileName = (char*)pnDes->Ptr();
00101   }
00102 
00103   GError* localError = NULL;
00104   gboolean ok = log_db_log_profile(iLogDb, aProfileId, profileName, &localError);
00105   guilogf("profile: %d (%s)", aProfileId, profileName);
00106   delete pnDes;
00107   if (!ok) {
00108     gx_dblog_fatal_error_free(iLogDb, localError);
00109     return;
00110   }
00111 }
00112 
00113 // The default empty implementation suits us fine.
00114 /*
00115 void CSensor_profile::HandleProfileActivationNotificationError(TInt)
00116 {
00117 }
00118 */
00119 
00120 #endif // __PROFILE_ENABLED__
00121 
00122 /**
00123 
00124 epoc-profile-31.cpp
00125 
00126 Copyright 2009 Helsinki Institute for Information Technology (HIIT)
00127 and the authors. All rights reserved.
00128 
00129 Authors: Tero Hasu <tero.hasu@hut.fi>
00130 
00131 Permission is hereby granted, free of charge, to any person
00132 obtaining a copy of this software and associated documentation files
00133 (the "Software"), to deal in the Software without restriction,
00134 including without limitation the rights to use, copy, modify, merge,
00135 publish, distribute, sublicense, and/or sell copies of the Software,
00136 and to permit persons to whom the Software is furnished to do so,
00137 subject to the following conditions:
00138 
00139 The above copyright notice and this permission notice shall be
00140 included in all copies or substantial portions of the Software.
00141 
00142 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00143 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00144 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00145 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
00146 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
00147 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00148 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
00149 SOFTWARE.
00150 
00151  **/

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