• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
19 #ifndef OSCL_DNS_METHOD_H_INCLUDED
20 #define OSCL_DNS_METHOD_H_INCLUDED
21 
22 #include "osclconfig_io.h"
23 #include "oscl_socket_types.h"
24 #include "oscl_scheduler_ao.h"
25 #include "oscl_dns.h"
26 #include "pvlogger.h"
27 
28 class OsclDNSObserver;
29 class OsclDNSRequestAO;
30 class OsclSocketServ;
31 class OsclDNSI;
32 class OsclDNS;
33 
34 /** This is the base class for all socket methods.
35 * It provides the timeout on socket requests.
36 */
37 class OsclDNSMethod : public OsclTimerObject
38 {
39     public:
OsclDNSMethod(Oscl_DefAlloc & a,const char * name,TPVDNSFxn fxn)40         OsclDNSMethod(Oscl_DefAlloc &a, const char *name, TPVDNSFxn fxn)
41                 : OsclTimerObject(OsclActiveObject::EPriorityNominal, name)
42                 , iDNSObserver(NULL)
43                 , iId(0)
44                 , iAlloc(a)
45                 , iDNSFxn(fxn)
46                 , iDNSRequestAO(NULL)
47         {
48             iLogger = PVLogger::GetLoggerObject("oscldns");
49         }
50 
51         void Abort();
52         void AbortAll();
53         void CancelMethod();
54         void Run();
55 
56         OsclDNSObserver *iDNSObserver;
57         uint32 iId;
58         Oscl_DefAlloc &iAlloc;
59         TPVDNSFxn iDNSFxn;
60         PVLogger* iLogger;
61 
62     protected:
63         void ConstructL(
64             OsclDNSObserver*aObserver,
65             OsclDNSRequestAO *aAO,
66             uint32 aId);
67 
68         bool StartMethod(int32 aTimeoutMsec);
69         void MethodDone();
70 
71         OsclDNSRequestAO *iDNSRequestAO;
72 };
73 
74 
75 /** This is the base class for all requests to the
76 * socket server.
77 */
78 class OsclDNSRequestAO : public OsclActiveObject
79 {
80     protected:
81 
OsclDNSRequestAO(const char * name)82         OsclDNSRequestAO(const char *name)
83                 : OsclActiveObject(OsclActiveObject::EPriorityNominal, name)
84                 , iDNSI(NULL)
85                 , iDNSMethod(NULL)
86                 , iSocketError(0)
87         {
88         }
89 
ConstructL(OsclDNSI * aDNS,OsclDNSMethod * aMethod)90         void ConstructL(
91             OsclDNSI *aDNS,
92             OsclDNSMethod *aMethod)
93         {
94             if (!aMethod)
95                 OsclError::Leave(OsclErrGeneral);
96             iDNSMethod = aMethod;
97             iLogger = iDNSMethod->iLogger;
98             if (!aDNS)
99                 OsclError::Leave(OsclErrGeneral);
100             iDNSI = aDNS;
101         }
102 
Abort()103         void Abort()
104         {
105             Cancel();
106             RemoveFromScheduler();
107         }
108         void NewRequest();
109         void RequestDone();
110         int GetSocketError();
111         OsclSocketServI *Serv();
112         void DoCancel();
113         void Run();
114 
Success()115         virtual void Success() {}
116 
117         OsclDNSI *iDNSI;
118         OsclDNSMethod *iDNSMethod;
119         int32 iSocketError;
120         PVLogger* iLogger;
121 
122         friend class OsclDNSI;
123         friend class OsclDNSMethod;
124         friend class OsclDNSRequest;
125         friend class DNSRequestParam;
126 };
127 
128 #endif
129 
130