1 /* ------------------------------------------------------------------ 2 * Copyright (C) 1998-2009 PacketVideo 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 13 * express or implied. 14 * See the License for the specific language governing permissions 15 * and limitations under the License. 16 * ------------------------------------------------------------------- 17 */ 18 // -*- c++ -*- 19 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 20 21 // O S C L _ D N S 22 23 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 24 25 /*! \addtogroup osclio OSCL IO 26 * 27 * @{ 28 */ 29 30 31 /*! \file oscl_dns.h 32 \brief The file oscl_socket.h defines the OSCL DNS APIs. 33 34 */ 35 #ifndef OSCL_DNS_H_INCLUDED 36 #define OSCL_DNS_H_INCLUDED 37 38 #ifndef OSCLCONFIG_IO_H_INCLUDED 39 #include "osclconfig_io.h" 40 #endif 41 42 #ifndef OSCL_SOCKET_TYPES_H_INCLUDED 43 #include "oscl_socket_types.h" 44 #endif 45 46 #ifndef OSCL_DEFALLOC_H_INCLUDED 47 #include "oscl_defalloc.h" 48 #endif 49 50 #ifndef OSCL_SOCKET_H_INCLUDED 51 #include "oscl_socket.h" 52 #endif 53 54 enum TPVDNSFxn 55 { 56 EPVDNSGetHostByName 57 } ; 58 59 enum TPVDNSEvent 60 { 61 EPVDNSSuccess 62 , EPVDNSPending 63 , EPVDNSTimeout 64 , EPVDNSFailure 65 , EPVDNSCancel 66 } ; 67 68 /** 69 * DNS event observer. The client implements this to get 70 * asynchronous command completion. 71 */ 72 class OsclDNSObserver 73 { 74 public: 75 /** 76 * DNS Event callback. 77 * 78 * @param aId: The ID that was supplied when 79 * the DNS object was created. 80 * @param aEvent: Function completion event. Will be 81 * EPVDNSSuccess, EPVDNSTimeout, or EPVDNSFailure. 82 * @param aError: When the event is EPVDNSFailure, this 83 * may contain a platform-specific error code, or zero if 84 * none is available. 85 */ 86 OSCL_IMPORT_REF virtual void HandleDNSEvent(int32 aId, TPVDNSFxn aFxn, TPVDNSEvent aEvent, int32 aError) = 0; 87 ~OsclDNSObserver()88 virtual ~OsclDNSObserver() {} 89 }; 90 91 class OsclGetHostByNameMethod; 92 class OsclDNSI; 93 94 /** 95 * The DNS class 96 */ 97 class OsclDNS: public HeapBase 98 { 99 public: 100 /** 101 * DNS object creation. 102 * 103 * @param alloc: Memory allocator 104 * @param aServ: Socket server. 105 * @param aObserver: DNS Event observer 106 * @param aId: Unique ID for this DNS object. This ID 107 * will be included in all callbacks associated with 108 * this DNS object. 109 */ 110 OSCL_IMPORT_REF static OsclDNS* NewL( 111 Oscl_DefAlloc &alloc, 112 OsclSocketServ& aServ, 113 OsclDNSObserver & aObserver, 114 uint32 aId); 115 116 /** 117 * Destructor. 118 * 119 * Note: the application must de-allocate the DNS object 120 * using the same allocator that was passed in the 121 * NewL object creation call. 122 */ 123 OSCL_IMPORT_REF ~OsclDNS(); 124 125 /** 126 * GetHostByName. 127 * This is an asynchronous method. 128 * 129 * @param name: Null-terminated string containing the host 130 * name. 131 * @param addr: The output address. The ipAddr field will 132 * contain the network address of the host in dotted decimal 133 * notation. 134 * @param aTimeoutMsec: A timeout for the request in milliseconds, 135 * or (-1) to indicate infinite wait. 136 * @returns: EPVDNSPending for success, EPVDNSFailure for failure. 137 */ 138 OSCL_IMPORT_REF TPVDNSEvent GetHostByName(char *name, OsclNetworkAddress& addr, 139 int32 aTimeoutMsec = -1); 140 141 /** 142 * Cancel GetHostByName 143 * 144 * This method will cancel any pending GetHostByName operation 145 * on the current object, causing the GetHostByName to complete 146 * with error EPVDNSCancel. If there is no pending 147 * GetHostByName operation, this method will have no effect. 148 */ 149 OSCL_IMPORT_REF void CancelGetHostByName(); 150 151 private: 152 OsclDNS( 153 Oscl_DefAlloc &alloc, 154 OsclDNSObserver& obs, 155 uint32 id); 156 void ConstructL(OsclSocketServ &aServ); 157 158 OsclGetHostByNameMethod* iGetHostByNameMethod; 159 Oscl_DefAlloc& iAlloc; 160 OsclDNSObserver& iObserver; 161 uint32 iId; 162 OsclDNSI *iDNS; 163 friend class OsclDNSRequestAO; 164 165 }; 166 167 168 169 #endif 170 171