|
S60 3rd Edition SDK for Symbian OS Example Applications Guide |
00001 /* 00002 * ============================================================================== 00003 * Name : AddressBookEngine.h 00004 * Part of : AddressBook 00005 * Interface : 00006 * Description : Application Engine class, CAddressBookEngine - 00007 * performs engine related operations 00008 * Version : 00009 * 00010 * Copyright (c) 2002-2006 Nokia Corporation. 00011 * This material, including documentation and any related 00012 * computer programs, is protected by copyright controlled by 00013 * Nokia Corporation. 00014 * ============================================================================== 00015 */ 00016 00017 #ifndef ADDRESSBOOKENGINE_H 00018 #define ADDRESSBOOKENGINE_H 00019 00020 // INCLUDES 00021 #include <flogger.h> 00022 00023 #include <SenServiceConnection.h> 00024 #include <SenXmlServiceDescription.h> 00025 #include <SenBaseFragment.h> 00026 #include <SenXmlReader.h> 00027 00028 #include "AddressBookContact.h" 00029 #include "MAddressBookEngineObserver.h" 00030 00031 #include <SenSoapMessage.h> 00032 #include <SenElement.h> 00033 #include <SenBaseElement.h> 00034 00035 // CONSTANTS 00036 _LIT8(KTooManyMatches, "TooManyMatches"); 00037 _LIT8(KStatus, "Status"); 00038 _LIT8(KCode, "code"); 00039 _LIT8(KOk, "OK"); 00040 _LIT8(KCard, "Card"); 00041 00042 _LIT8(KQueryNS, "ab"); // Namespace identifier 00043 00044 _LIT8(KResourceIDVal, "XYZ"); // Contents of Resource Tag 00045 00046 _LIT8(KEncrypted, "Encrypted"); // Identifier for encrypted resource ID's 00047 00048 // Query to be sent to service, contents of Select Tag 00049 _LIT8(KSelectQuery, "/ab:Card[contains(ab:N/ab:FAMILY,'%S') or contains(ab:N/ab:GIVEN,'%S') or contains(ab:TEL,'%S')]"); 00050 00051 // MACROS 00052 // for logging only 00053 _LIT(KLogDir, "AddressBook"); 00054 _LIT(KLogFile, "AddressBook.log"); 00055 _LIT(KLogOpeningLine, "CAddressBookEngine::ConstructL - log file opened."); 00056 00057 #define LOG_OPEN() \ 00058 RFileLogger::Write(KLogDir, KLogFile, EFileLoggingModeOverwrite, KLogOpeningLine); 00059 00060 #define LOG(string) \ 00061 RFileLogger::Write(KLogDir, KLogFile, EFileLoggingModeAppend, string); 00062 00063 #define LOG_FORMAT(params) \ 00064 RFileLogger::WriteFormat(KLogDir, KLogFile, EFileLoggingModeAppend, params); 00065 00066 #define LOG_ALL(longstring) \ 00067 { \ 00068 TInt ___iLogZ___ = 0; \ 00069 TInt ___amountLogZ___ = 100; \ 00070 while(___iLogZ___<longstring.Length()) \ 00071 { \ 00072 if(( longstring.Length()-___iLogZ___) < 100) \ 00073 ___amountLogZ___ = longstring.Length()-___iLogZ___; \ 00074 LOG(longstring.Mid(___iLogZ___,___amountLogZ___)); \ 00075 ___iLogZ___+=100; \ 00076 } \ 00077 } 00078 00079 // DATA TYPES 00080 enum TErrorState 00081 { 00082 ENoError = 0, 00083 ESoapError, 00084 ENestedError 00085 }; 00086 00087 // FORWARD DECLARATIONS 00088 class CSenServiceManager; 00089 00090 // CLASS DECLARATION 00091 00092 /** 00093 * Application Engine class 00094 * performs engine related operations 00095 */ 00096 class CAddressBookEngine : public CSenBaseFragment, public MSenServiceConsumer 00097 { 00098 public: // Constructors and destructor 00099 00100 /** 00101 * Two-phased constructor 00102 */ 00103 static CAddressBookEngine* NewL(MAddressBookEngineObserver& aObserver); 00104 00105 /** 00106 * Destructor. 00107 */ 00108 ~CAddressBookEngine(); 00109 00110 // New functions 00111 00112 /** 00113 * This function is called after an user has selected Search from the GUI 00114 * and typed a request. Function creates a search pattern from the descriptor 00115 * and send it to the WSP. The message from server is received through 00116 * HandleMessageL() or an error is received through HandleErrorL(). 00117 * @param aSearchPattern - descriptor on Searching note that an user has typed 00118 */ 00119 void SendSearchL(const TDesC& aSearchPattern); 00120 00121 /** 00122 * Makes a connection to an ID-WSF service. 00123 * When ConnectL() is called the first time, authentication and 00124 * discovery services are connected and the user is therefore 00125 * authenticated and the service is connected. 00126 * When ConnectL() is called again and the credentials received from 00127 * authentication and discovery services are valid, there are no need to 00128 * connect to them again. This means that SetStatus() will be called 00129 * almost immediately with value CONNECTED, but in device GPRS or data 00130 * connection is not opened yet (but instead it is opened when search 00131 * occurs). 00132 */ 00133 void ConnectL(); 00134 00135 /** 00136 * sets a state of connection as KSenConnectionStatusReady 00137 */ 00138 TBool Connected(); 00139 00140 /** 00141 * This function need to get a current contact (CAddressBookView::CurrentContact()) 00142 * or to open an item (CAddressBookView::OpenItemL()) 00143 * @param aPosition - Index of Item whose data is needed to get 00144 * @param aContact - gets Value of Item whose Index == aPosition 00145 * @return if there is such item, KErrorNotFound is returned 00146 * otherwise returns KIndexError. 00147 */ 00148 TInt GetContact(TInt aPosition, CAddressBookContact*& aContact); 00149 00150 /** 00151 * Close WebServices-connection if user canceled 00152 */ 00153 void Cancel(); 00154 00155 /** 00156 * Gets the XML query based on the search parameter passed 00157 * Method also calls WSF ServiceDescriptionL() getter and 00158 * resolves either ResourceID or EncryptedResourceID element. Later 00159 * on, this resource id may be used when generating the actual query 00160 * which is sent to the service (WSP) 00161 * @param aSearchPattern - descriptor on Searching note that an user has typed 00162 */ 00163 HBufC8* GenerateQueryRequestL(const TDesC& aSearchPattern); 00164 00165 protected: // Functions from base classes 00166 00167 /** 00168 * From CSenDomFragment, is called from CAddressBookEngine::HandleMessageL 00169 * (ParseL(aMessage)) every time when XML parser finds a new element tag. 00170 * In this case we are interested in the <Status> and <Card> elements. 00171 * When Status is found, we compare if attribute 'Code' is OK or not. 00172 * SenXmlUtils::LocalName() only extracts out a possible XML prefix 00173 * (i.e. 'ab:OK'). 00174 * When local name is 'Card', we have encountered a contact-object. 00175 * Then we make a new CAddressBookContact and delegate the parsing to it. 00176 * 00177 * Example server response: 00178 * <ab:QueryResponse xmlns:ab="urn:nokia:test:addrbook:2004-09"> 00179 * <ab:Status code="ab:OK"/> 00180 * <ab:Data> 00181 * <ab:Card> 00182 * <ab:N> 00183 * <ab:FAMILY>Smith</ab:FAMILY> 00184 * <ab:GIVEN>John</ab:GIVEN> 00185 * </ab:N> 00186 * <ab:ADR> 00187 * <ab:EXTADR>Room 123</ab:EXTADDR> 00188 * <ab:STREET>1st ST 123</ab:STREET> 00189 * <ab:PCODE>7698532</ab:PCODE> 00190 * </ab:ADR> 00191 * <ab:TEL>1234</ab:TEL> 00192 * <ab:TEL type="CELL">2122345</ab:TEL> 00193 * </ab:Card> 00194 * </ab:Data> 00195 * </ab:QueryResponse> 00196 * 00197 * @param aNsUri - namespace URI 00198 * @param aLocalName - local name (in this case may be Status or Card) 00199 * @param aQName - qualified name 00200 * @param aAttrs - we are interested if value of attribute is KCode or not 00201 */ 00202 virtual void StartElementL(const TDesC8& aNsUri, 00203 const TDesC8& aLocalName, 00204 const TDesC8& aQName, 00205 const RAttributeArray& aAttrs); 00206 00207 /** 00208 * From CSenDomFragment, is called from CAddressBookEngine::HandleMessageL 00209 * (ParseL(aMessage)) every time when XML parser finds a closing element tag. 00210 * 00211 * We are only interested about the </Status> element. 00212 * When the </Status> is found, we check for errors found in response, 00213 * and if so, notice the observer 00214 * @param aNsUri - namespace URI 00215 * @param aLocalName - local name (in this case we are interested only Status) 00216 * @param aQName - qualified name 00217 */ 00218 virtual void EndElementL(const TDesC8& aNsUri, 00219 const TDesC8& aLocalName, 00220 const TDesC8& aQName); 00221 00222 private: // Constructor 00223 00224 /** 00225 * C++ default constructor. 00226 */ 00227 CAddressBookEngine(MAddressBookEngineObserver& aObserver); 00228 00229 /** 00230 * By default Symbian 2nd phase constructor is private. 00231 */ 00232 void ConstructL(); 00233 00234 00235 // New functions 00236 00237 /** 00238 * Register IdentityProvider and associates Forum Nokia's Addressbook 00239 * service to be known to trust in this IDP. Method creates instance 00240 * of the CSenServiceManager to achieve this Identity Provider (IDP) 00241 * registration. IDP is also registered as Authentication Service (AS) 00242 * Description, because in Liberty ID-WSF, they are the same service. 00243 * @return status code or -1 if error appears 00244 */ 00245 TInt RegisterIdentityProviderL(); 00246 00247 // Functions from base classes 00248 00249 /** 00250 * From MSenServiceConsumer, handles receiving messages from the SendL() 00251 * (CSenServiceConnection)function call 00252 * @param aMessage - descriptor on content of receiving Message 00253 */ 00254 virtual void HandleMessageL(const TDesC8& aMessage); 00255 00256 /** 00257 * From MSenServiceConsumer, handles receiving errors about the connection to be initialized 00258 * or from the SendL()(CSenServiceConnection)function call 00259 * @param aErrorCode - code of error 00260 * @param aError - descriptor on content of receiving Error 00261 */ 00262 virtual void HandleErrorL(const TInt aErrorCode, 00263 const TDesC8& aError); 00264 00265 /** 00266 * From MSenServiceConsumer, handles receiving status info about the connection 00267 * to be initialized. Is called by CSenServiceConnectionImpl::RunL() 00268 * that is called by active scheduler from CAddressBookAppUi::HandleCommandL(TInt aCommand) 00269 * in case "EAddressBookCmdAppConnect" 00270 * @param aStatus - may be 00271 * KSenConnectionStatusNew, 00272 * KSenConnectionStatusReady, 00273 * or STATUS_EXRIRED 00274 */ 00275 virtual void SetStatus(const TInt aStatus); 00276 00277 /** 00278 * This helper function resolves the ResourceID from WSF using 00279 * ServiceDescriptionL() getter method. 00280 * @return pointer to resolved ResourceID element, 00281 * which content indicates whether it is 00282 * encrypted or not; content of encrypted 00283 * ResourceID includes "EncryptedData" 00284 * element. 00285 */ 00286 virtual CSenElement* ResolveResourceIdL(); 00287 00288 00289 private: // Data 00290 RPointerArray<CAddressBookContact> iContacts; 00291 TInt iConnectionState; 00292 CSenServiceConnection* iConnection; 00293 CSenXmlServiceDescription* iSession; 00294 00295 CSenXmlReader* iXmlReader; 00296 00297 MAddressBookEngineObserver& iObserver; 00298 CSenServiceManager* iManager; 00299 CSenDomFragment* iFaultDelegate; 00300 TInt iErrorState; 00301 00302 // turns to ETrue after first successfull init. 00303 TBool iInitialized; 00304 }; 00305 00306 #endif // ADDRESSBOOKENGINE_H 00307 00308 // End of File 00309
|
© Nokia 2006 |