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_TYPES_H_INCLUDED 21 #define OSCL_SOCKET_TYPES_H_INCLUDED 22 23 #include "osclconfig_io.h" 24 #include "oscl_types.h" 25 #include "oscl_scheduler_types.h" 26 #include "oscl_namestring.h" 27 #include "oscl_stdstring.h" 28 29 enum TPVSocketFxn 30 { 31 EPVSocketSend = 0 32 , EPVSocketSendTo 33 , EPVSocketRecv 34 , EPVSocketRecvFrom 35 , EPVSocketConnect 36 , EPVSocketAccept 37 , EPVSocketShutdown 38 , EPVSocketBind 39 , EPVSocketListen 40 , EPVSocket_Last //placeholder 41 } ; 42 43 /** Return codes for asynchronous APIs 44 */ 45 enum TPVSocketEvent 46 { 47 EPVSocketSuccess 48 , EPVSocketPending 49 , EPVSocketTimeout 50 , EPVSocketFailure 51 , EPVSocketCancel 52 } ; 53 54 enum TPVSocketShutdown 55 { 56 EPVSocketSendShutdown 57 , EPVSocketRecvShutdown 58 , EPVSocketBothShutdown 59 } ; 60 61 #define PVNETWORKADDRESS_LEN 50 62 63 class OsclNetworkAddress 64 { 65 public: OsclNetworkAddress()66 OsclNetworkAddress(): port(0) 67 { 68 } OsclNetworkAddress(const char * addr,int p)69 OsclNetworkAddress(const char *addr, int p) 70 { 71 ipAddr.Set(addr); 72 port = p; 73 } 74 75 //Network address in dotted decimal string format. 76 OsclNameString<PVNETWORKADDRESS_LEN> ipAddr; 77 78 //Port number. 79 int port; 80 //@cmember equality comparison operator 81 bool operator == (const OsclNetworkAddress & rhs) const 82 { 83 if (port == rhs.port) 84 { 85 if (0 == oscl_strcmp((const char*)ipAddr.Str(), (const char*)rhs.ipAddr.Str())) 86 return true; 87 } 88 return false; 89 }; 90 91 } ; 92 93 /** 94 * Socket event observer. The client implements this to get 95 * asynchronous command completion. 96 */ 97 class OsclSocketObserver 98 { 99 public: 100 /** 101 * Socket Event callback. 102 * 103 * @param aId: The ID that was supplied when 104 * the socket was created. 105 * @param aFxn: Type of socket function call. 106 * @param aEvent: Function completion event. Will be 107 * EPVSocketSuccess, EPVSocketTimeout, or EPVSocketFailure. 108 * @param aError: When the event is EPVSocketFailure, this 109 * may contain a platform-specific error code, or zero if 110 * none is available. 111 */ 112 OSCL_IMPORT_REF virtual void HandleSocketEvent(int32 aId, TPVSocketFxn aFxn, TPVSocketEvent aEvent, int32 aError) = 0; ~OsclSocketObserver()113 virtual ~OsclSocketObserver() {} 114 }; 115 116 117 #endif 118