• 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_UDP_SOCKET_H_INCLUDED
20 #define OSCL_UDP_SOCKET_H_INCLUDED
21 
22 #include "oscl_ip_socket.h"
23 #include "oscl_defalloc.h"
24 
25 class OsclSendToMethod;
26 class OsclRecvFromMethod;
27 class OsclBindMethod;
28 
29 /**Internal implementation class for OsclUDPSocket
30 */
31 class OsclUDPSocketI : public OsclIPSocketI
32 {
33     public:
34         static OsclUDPSocketI *NewL(Oscl_DefAlloc &a,
35                                     OsclSocketServI *aServ,
36                                     OsclSocketObserver *aObserver,
37                                     uint32 aId);
38 
39         virtual ~OsclUDPSocketI();
40 
41         //Synchronous methods
42         int32 Close();
43         inline uint8 *GetRecvData(int32 *aLength);
44         inline uint8 *GetSendData(int32 *aLength);
45 
46         //Asynchronous methods
47         inline TPVSocketEvent BindAsync(OsclNetworkAddress& aAddress,
48                                         int32 aTimeoutMsec = -1);
49         inline void CancelBind();
50 
51         inline TPVSocketEvent SendTo(const uint8* &aPtr, uint32 aLen,
52                                      OsclNetworkAddress& aAddress,
53                                      int32 aTimeoutMsec = -1);
54         inline void CancelSendTo();
55 
56         inline TPVSocketEvent RecvFrom(uint8* &aPtr, uint32 aMaxLen,
57                                        OsclNetworkAddress& aAddress,
58                                        int32 aTimeoutMsec = -1,
59                                        uint32 aMultiMaxLen = 0,
60                                        Oscl_Vector<uint32, OsclMemAllocator>* aPacketLen = NULL,
61                                        Oscl_Vector<OsclNetworkAddress, OsclMemAllocator>* aPacketSource = NULL);
62         inline void CancelRecvFrom();
63 
64     private:
OsclUDPSocketI(Oscl_DefAlloc & a)65         OsclUDPSocketI(Oscl_DefAlloc &a) : OsclIPSocketI(a), iSendToMethod(NULL),
66                 iRecvFromMethod(NULL)
67         {}
68 
69         void ConstructL(OsclSocketServI *aServ,
70                         OsclSocketObserver *aObserver,
71                         uint32 aId);
72 
73         OsclBindMethod *iBindMethod;
74         OsclSendToMethod *iSendToMethod;
75         OsclRecvFromMethod *iRecvFromMethod;
76 };
77 
78 #include "oscl_socket_recv_from.h"
79 #include "oscl_socket_send_to.h"
80 #include "oscl_socket_bind.h"
81 
82 //////////////////////////////////////////////////////////////////////////////////
GetRecvData(int32 * aLength)83 inline uint8 *OsclUDPSocketI::GetRecvData(int32 *aLength)
84 {
85     return iRecvFromMethod->GetRecvData(aLength);
86 }
87 
88 //////////////////////////////////////////////////////////////////////////////////
GetSendData(int32 * aLength)89 inline uint8 *OsclUDPSocketI::GetSendData(int32 *aLength)
90 {
91     return iSendToMethod->GetSendData(aLength);
92 }
93 
94 //////////////////////////////////////////////////////////////////////////////////
BindAsync(OsclNetworkAddress & aAddress,int32 aTimeoutMsec)95 inline TPVSocketEvent OsclUDPSocketI::BindAsync(OsclNetworkAddress& aAddress,
96         int32 aTimeoutMsec)
97 {
98     if (!OsclSocketIBase::HasAsyncBind())
99         return EPVSocketFailure;//not available.
100 
101     iAddress.ipAddr.Set(aAddress.ipAddr.Str());
102     iAddress.port = aAddress.port;
103     return (iBindMethod->Bind(aAddress, aTimeoutMsec));
104 }
105 
CancelBind()106 inline void OsclUDPSocketI::CancelBind()
107 {
108     iBindMethod->CancelMethod();
109 }
110 
111 //////////////////////////////////////////////////////////////////////////////////
SendTo(const uint8 * & aPtr,uint32 aLen,OsclNetworkAddress & aAddress,int32 aTimeoutMsec)112 inline TPVSocketEvent OsclUDPSocketI::SendTo(const uint8* &aPtr, uint32 aLen,
113         OsclNetworkAddress& aAddress,
114         int32 aTimeoutMsec)
115 {
116     return (iSendToMethod->SendTo(aPtr, aLen, aAddress, aTimeoutMsec));
117 }
118 
CancelSendTo()119 inline void OsclUDPSocketI::CancelSendTo()
120 {
121     iSendToMethod->CancelMethod();
122 }
123 
124 //////////////////////////////////////////////////////////////////////////////////
RecvFrom(uint8 * & aPtr,uint32 aMaxLen,OsclNetworkAddress & aAddress,int32 aTimeoutMsec,uint32 aMultiMax,Oscl_Vector<uint32,OsclMemAllocator> * aPacketLen,Oscl_Vector<OsclNetworkAddress,OsclMemAllocator> * aPacketSource)125 inline TPVSocketEvent OsclUDPSocketI::RecvFrom(uint8* &aPtr, uint32 aMaxLen,
126         OsclNetworkAddress& aAddress,
127         int32 aTimeoutMsec, uint32 aMultiMax,
128         Oscl_Vector<uint32, OsclMemAllocator>* aPacketLen,
129         Oscl_Vector<OsclNetworkAddress, OsclMemAllocator>* aPacketSource)
130 {
131     return (iRecvFromMethod->RecvFrom(aPtr, aMaxLen, aAddress, aTimeoutMsec, aMultiMax, aPacketLen, aPacketSource));
132 }
133 
CancelRecvFrom()134 inline void OsclUDPSocketI::CancelRecvFrom()
135 {
136     iRecvFromMethod->CancelMethod();
137 }
138 
139 #endif
140 
141