epoc-cellid.cpp

Go to the documentation of this file.
00001 #include "epoc-cellid.hpp"
00002 
00003 #if __CELLID_ENABLED__
00004 
00005 #include "er_errors.h"
00006 #include "ld_logging.h"
00007 #include "sa_sensor_list_log_db.h"
00008 #include "utils_cl2.h"
00009 
00010 #include "common/utilities.h"
00011 
00012 // -------------------------------------------------------------------
00013 // the sensor object implementation...
00014 
00015 CTOR_IMPL_CSensor_cellid;
00016 
00017 static void DataChanged(bb_Blackboard* self, enum bb_DataType dt,
00018       gpointer data, int len, gpointer arg)
00019 {
00020   (void)self;
00021   (void)dt;
00022   (void)len;
00023   CSensor_cellid* sensor = (CSensor_cellid*)arg;
00024   CTelephony::TNetworkInfoV1* info = (CTelephony::TNetworkInfoV1*)data;
00025   sensor->PostNewData(*info);
00026 }
00027 
00028 void CSensor_cellid::ConstructL()
00029 {
00030   iClosure.changed = DataChanged;
00031   iClosure.arg = this;
00032   if (!bb_Blackboard_register(GetBlackboard(),
00033             bb_dt_cell_id,
00034             iClosure,
00035             NULL))
00036     User::LeaveNoMemory();
00037 }
00038 
00039 CSensor_cellid::~CSensor_cellid()
00040 {
00041   Unregister();
00042 }
00043 
00044 void CSensor_cellid::Unregister()
00045 {
00046   bb_Blackboard_unregister(GetBlackboard(), iClosure);
00047 }
00048 
00049 void CSensor_cellid::PostNewData(const CTelephony::TNetworkInfoV1& aData)
00050 {
00051   TRAPD(errCode, PostNewDataL(aData));
00052   if (errCode) {
00053     er_log_symbian(er_FATAL, errCode, 
00054        "failure processing network info in cellid sensor");
00055   }
00056 }
00057 
00058 void CSensor_cellid::PostNewDataL(const CTelephony::TNetworkInfoV1& aData)
00059 {
00060   // Logging is not all that straightforward here, as some readings
00061   // can for instance indicate that some or all of the usual
00062   // (country_code, network_code, area_code, cell_id) information is
00063   // not available or has just become unavailable. Our present
00064   // solution is to log nothing unless all of that information is
00065   // available.
00066   if (!aData.iAccess) {
00067     //logg("cellid info: no network access: iAreaKnown=%d", (int)aData.iAreaKnown);
00068   } else {
00069     // Here we are assuming that the initial "zero" iOldData is not
00070     // a valid reading, and likely this is true as it would mean no
00071     // country code or network ID. And duplicates can still occur,
00072     // across sensor restarts. This should nonetheless help reduce
00073     // the amount of logged data quite a bit, as it seems that in
00074     // practice one gets around 2-4 cell ID events per minute even
00075     // when there is no cell change.
00076     if ((iOldData.iCountryCode == aData.iCountryCode) &&
00077   (iOldData.iNetworkId == aData.iNetworkId) &&
00078   (iOldData.iLocationAreaCode == aData.iLocationAreaCode) &&
00079   (iOldData.iCellId == aData.iCellId)) {
00080       // Same reading as previously.
00081       //logt("duplicate cell ID reading");
00082     } else {
00083       //logt("new cell ID reading");
00084       iOldData = aData;
00085 
00086       // In practice it seems that countryCode and networkCode are
00087       // decimal strings, but this may only apply to GSM networks, and
00088       // hence we are treating them as strings. Whoever parses the
00089       // database content may decide to do something different if they
00090       // see that all the data indeed is decimal strings.
00091       // http://en.wikipedia.org/wiki/List_of_mobile_country_codes
00092       // http://en.wikipedia.org/wiki/Mobile_Network_Code
00093       HBufC8* countryCode = ConvToUtf8ZL(aData.iCountryCode);
00094       CleanupStack::PushL(countryCode);
00095       HBufC8* networkCode = ConvToUtf8ZL(aData.iNetworkId);
00096       CleanupStack::PushL(networkCode);
00097       int areaCode = aData.iLocationAreaCode; // valid if iAccess is true
00098       int cellId = aData.iCellId; // valid if iAccess is true
00099 
00100       const char* cCountryCode = (const char*)(countryCode->Ptr());
00101       const char* cNetworkCode = (const char*)(networkCode->Ptr());
00102 
00103       log_db_log_cellid(GetLogDb(), 
00104       cCountryCode,
00105       cNetworkCode,
00106       areaCode, cellId, NULL);
00107       guilogf("cellid: (%s, %s, %d, %d)", 
00108         cCountryCode, cNetworkCode, areaCode, cellId);
00109 
00110       CleanupStack::PopAndDestroy(2); // networkCode, countryCode
00111     }
00112   }
00113 }
00114 
00115 #endif // __CELLID_ENABLED__
00116 
00117 /**
00118 
00119 epoc-cellid.cpp
00120 
00121 Copyright 2009 Helsinki Institute for Information Technology (HIIT)
00122 and the authors. All rights reserved.
00123 
00124 Authors: Tero Hasu <tero.hasu@hut.fi>
00125 
00126 Permission is hereby granted, free of charge, to any person
00127 obtaining a copy of this software and associated documentation files
00128 (the "Software"), to deal in the Software without restriction,
00129 including without limitation the rights to use, copy, modify, merge,
00130 publish, distribute, sublicense, and/or sell copies of the Software,
00131 and to permit persons to whom the Software is furnished to do so,
00132 subject to the following conditions:
00133 
00134 The above copyright notice and this permission notice shall be
00135 included in all copies or substantial portions of the Software.
00136 
00137 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00138 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00139 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00140 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
00141 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
00142 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00143 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
00144 SOFTWARE.
00145 
00146  **/

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