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 20 #ifndef OSCL_SOCKET_IMP_PV_H_INCLUDED 21 #define OSCL_SOCKET_IMP_PV_H_INCLUDED 22 23 #include "oscl_socket_imp_base.h" 24 25 /*! Socket implementation for PV socket server 26 */ 27 28 /** some error codes for request completion 29 ** these are negative so they won't conflict with 30 ** errors from the OS socket layer. 31 */ 32 #define PVSOCK_ERR_BAD_PARAM (-1) 33 #define PVSOCK_ERR_SOCK_NOT_OPEN (-2) 34 #define PVSOCK_ERR_SOCK_NO_SERV (-3) 35 #define PVSOCK_ERR_SERV_NOT_CONNECTED (-4) 36 #define PVSOCK_ERR_SOCK_NOT_CONNECTED (-5) 37 #define PVSOCK_ERR_NOT_IMPLEMENTED (-6) 38 39 40 class OsclSocketServI; 41 class PVLogger; 42 class OsclSocketServRequestQElem; 43 44 /** Socket implementation class 45 */ 46 class OsclSocketI: public OsclSocketIBase 47 { 48 public: 49 static OsclSocketI* NewL(Oscl_DefAlloc &a); 50 ~OsclSocketI(); 51 52 //synchronous methods 53 int32 Open(OsclSocketServI& aServer, uint32 addrFamily, uint32 sockType, uint32 protocol); 54 int32 Open(OsclSocketServI& aServer); 55 int32 Bind(OsclNetworkAddress& anAddr); 56 int32 Join(OsclNetworkAddress& anAddr); 57 int32 Close(); 58 int32 Listen(uint32 qSize); 59 int32 SetRecvBufferSize(uint32 size); 60 61 //asynchronous methods. 62 63 void Connect(ConnectParam& , OsclSocketRequestAO&); 64 65 void Accept(AcceptParam &, OsclSocketRequestAO&); 66 67 void Shutdown(ShutdownParam &, OsclSocketRequestAO&); 68 69 void Send(SendParam &, OsclSocketRequestAO&); 70 void SendSuccess(SendParam &); 71 72 void SendTo(SendToParam & , OsclSocketRequestAO&); 73 void SendToSuccess(SendToParam &); 74 75 void Recv(RecvParam &, OsclSocketRequestAO&); 76 void RecvSuccess(RecvParam &); 77 78 void RecvFrom(RecvFromParam &, OsclSocketRequestAO&); 79 void RecvFromSuccess(RecvFromParam &); 80 81 82 private: 83 OsclSocketI(Oscl_DefAlloc &a); 84 85 inline void CancelConnect(); 86 inline void CancelAccept(); 87 inline void CancelShutdown(); 88 inline void CancelSend(); 89 inline void CancelSendTo(); 90 inline void CancelRecv(); 91 inline void CancelRecvFrom(); 92 93 inline bool IsOpen(); 94 95 96 97 //PV socket server 98 99 //the OS-level socket 100 TOsclSocket iSocket; 101 102 public: Socket()103 TOsclSocket Socket() 104 { 105 return iSocket; 106 } 107 static bool MakeAddr(OsclNetworkAddress& in, TOsclSockAddr& addr); 108 static void MakeAddr(TOsclSockAddr& in, OsclNetworkAddress& addr); 109 110 //routines to handle each type of socket request under the 111 //server thread. 112 void ProcessConnect(OsclSocketServRequestQElem*); 113 void ProcessShutdown(OsclSocketServRequestQElem*); 114 void ProcessAccept(OsclSocketServRequestQElem*); 115 void ProcessSendTo(OsclSocketServRequestQElem*); 116 void ProcessRecvFrom(OsclSocketServRequestQElem*); 117 void ProcessSend(OsclSocketServRequestQElem*); 118 void ProcessRecv(OsclSocketServRequestQElem*); 119 120 private: 121 bool iSocketValid; 122 bool iSocketConnected; 123 void InitSocket(bool valid); 124 125 bool IsConnected(OsclSocketRequestAO& aObject); 126 bool IsReady(OsclSocketRequestAO& aObject); 127 128 //server requests 129 OsclSocketRequest iSockServAcceptRequest; 130 OsclSocketRequest iSockServConnectRequest; 131 OsclSocketRequest iSockServRecvRequest; 132 OsclSocketRequest iSockServRecvFromRequest; 133 OsclSocketRequest iSockServSendRequest; 134 OsclSocketRequest iSockServSendToRequest; 135 OsclSocketRequest iSockServShutdownRequest; 136 friend class OsclAcceptRequest; 137 friend class OsclConnectRequest; 138 friend class OsclRecvRequest; 139 friend class OsclRecvFromRequest; 140 friend class OsclSendRequest; 141 friend class OsclSendToRequest; 142 friend class OsclShutdownRequest; 143 144 friend class OsclUDPSocket; 145 friend class OsclTCPSocket; 146 147 PVLogger* iLogger; 148 149 public: 150 //for logging in socket request list. Logger()151 PVLogger* Logger() 152 { 153 return iLogger; 154 } 155 156 }; 157 158 #endif 159 160 161 162 163