epoc-profile.cpp

Go to the documentation of this file.
00001 #include "epoc-profile.hpp"
00002 
00003 #if __PROFILE_ENABLED__ && !__HAVE_PROFILEENGINE_LIB__
00004 
00005 #include "epoc-ao-gerror.hpp"
00006 #include "sa_sensor_list_log_db.h"
00007 #include "utils_cl2.h"
00008 
00009 #include "common/assertions.h"
00010 #include "er_errors.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 <mprofile.h>
00017 #include <mprofilename.h>
00018 
00019 // The caller must free the returned buffer. The buffer is guaranteed
00020 // to have a zero terminator.
00021 HBufC8* CSensor_profile::GetCurrentProfileNameL()
00022 {
00023   MProfile* profile = iProfileEngine->ActiveProfileL();
00024   CleanupReleasePushL(*profile);
00025 
00026   const MProfileName& 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   // xxx use the RFs* variant instead, as soon as other sensors need a handle
00053   iProfileEngine = CreateProfileEngineL();
00054 }
00055 
00056 CSensor_profile::~CSensor_profile()
00057 {
00058   delete iReader;
00059   if (iProfileEngine)
00060     {
00061       iProfileEngine->Release();
00062     }
00063 }
00064 
00065 gboolean CSensor_profile::StartL(GError** error)
00066 {
00067   if (!iReader) {
00068     // This starts observing right away, and we cannot cancel our
00069     // "subscription" without destroying the object.
00070     iReader = CProfileChangeNotifyHandler::NewL(this);
00071     //log_db_log_status(iLogDb, NULL, "profile sensor started");
00072   }
00073   return TRUE;
00074 }
00075 
00076 void CSensor_profile::Stop()
00077 {
00078   delete iReader;
00079   iReader = NULL;
00080   //log_db_log_status(iLogDb, NULL, "profile sensor stopped");
00081 }
00082 
00083 void CSensor_profile::HandleActiveProfileEventL(TProfileEvent aProfileEvent,
00084             TInt aProfileId)
00085 {
00086 #if 0
00087   { // test code...
00088     ex_txtlog_fatal_error(KErrGeneral);
00089   }
00090 #endif
00091 
00092   if (aProfileEvent == EProfileNewActiveProfile) {
00093     // We shall log 'aProfileId'.
00094     GError* error = NULL;
00095 
00096     // And we shall also log the current profile name, which hopefully
00097     // still corresponds to the ID. I guess in theory it might not, so
00098     // we might consider using and probably caching a
00099     // 'ProfilesNamesArrayLC' returned value instead.        xxx
00100     HBufC8* pnDes = NULL;
00101     TRAPD(errCode, pnDes = GetCurrentProfileNameL());
00102     char* profileName;
00103     if (errCode) {
00104       profileName = "";
00105       dblogg("could not get profile name for profile %d: %s (%d)", aProfileId, plat_error_strerror(errCode), errCode);
00106     } else {
00107       profileName = (char*)pnDes->Ptr();
00108     }
00109 
00110     gboolean ok = log_db_log_profile(iLogDb, aProfileId, profileName, &error);
00111     delete pnDes;
00112     if (!ok) {
00113       gx_txtlog_error_clear(&error);
00114       User::Leave(KErrWrite);
00115     }
00116   }
00117 }
00118 
00119 #endif // __PROFILE_ENABLED__
00120 
00121 /**
00122 
00123 epoc-profile.cpp
00124 
00125 Copyright 2009 Helsinki Institute for Information Technology (HIIT)
00126 and the authors. All rights reserved.
00127 
00128 Authors: Tero Hasu <tero.hasu@hut.fi>
00129 
00130 Permission is hereby granted, free of charge, to any person
00131 obtaining a copy of this software and associated documentation files
00132 (the "Software"), to deal in the Software without restriction,
00133 including without limitation the rights to use, copy, modify, merge,
00134 publish, distribute, sublicense, and/or sell copies of the Software,
00135 and to permit persons to whom the Software is furnished to do so,
00136 subject to the following conditions:
00137 
00138 The above copyright notice and this permission notice shall be
00139 included in all copies or substantial portions of the Software.
00140 
00141 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00142 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00143 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00144 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
00145 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
00146 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00147 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
00148 SOFTWARE.
00149 
00150  **/

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