00001
00002 #ifndef OSCL_SOCKET_METHOD_H_INCLUDED
00003 #define OSCL_SOCKET_METHOD_H_INCLUDED
00004
00005 #include "osclconfig_io.h"
00006 #include "oscl_socket_types.h"
00007
00008 #include "oscl_scheduler_ao.h"
00009 #include "oscl_socket_request.h"
00010 #include "pvlogger.h"
00011 #include "oscl_socket_tuneables.h"
00012 #include "oscl_ip_socket.h"
00013
00014 #define MSEC_TO_MICROSEC 1000
00015
00016 class OsclSocketI;
00017 class OsclSocketObserver;
00018 class OsclSocketRequestAO;
00019 class OsclIPSocketI;
00020
00026 class OsclSocketMethod : public OsclTimerObject
00027 {
00028 public:
00029 OsclSocketMethod(OsclIPSocketI& aContainer, const char *name, TPVSocketFxn fxn)
00030 : OsclTimerObject(PV_SOCKET_REQUEST_AO_PRIORITY, name)
00031 , iContainer(aContainer)
00032 , iSocketFxn(fxn)
00033 , iSocketRequestAO(NULL)
00034 {
00035 }
00036 virtual ~OsclSocketMethod()
00037 {}
00038
00039 void Abort()
00040 {
00041 Cancel();
00042 }
00043
00044 inline void AbortAll();
00045
00046 inline void CancelMethod();
00047
00048 OsclIPSocketI& iContainer;
00049
00050 TPVSocketFxn iSocketFxn;
00051
00052 Oscl_DefAlloc& Alloc()
00053 {
00054 return iContainer.Alloc();
00055 }
00056
00057 protected:
00058 void ConstructL(OsclSocketRequestAO *aAO)
00059 {
00060 if (!aAO)
00061 OsclError::Leave(OsclErrGeneral);
00062 iSocketRequestAO = aAO;
00063 }
00064
00065 bool StartMethod(int32 aTimeoutMsec);
00066
00067 inline void MethodDone();
00068
00069 void Run();
00070
00071 OsclSocketRequestAO *iSocketRequestAO;
00072 };
00073
00074 #include "oscl_socket_imp.h"
00075
00080 class OsclSocketRequestAO : public OsclActiveObject
00081 {
00082 public:
00083 void ConstructL()
00084 {
00085 }
00086 protected:
00087
00088 OsclSocketRequestAO(OsclSocketMethod& aContainer, const char *name)
00089 : OsclActiveObject(PV_SOCKET_REQUEST_AO_PRIORITY, name)
00090 , iContainer(aContainer)
00091 , iSocketError(0)
00092 , iParam(NULL)
00093 , iParamSize(0)
00094 {}
00095
00096 virtual ~OsclSocketRequestAO()
00097 {
00098 CleanupParam(true);
00099 }
00100
00101 OsclAny* NewRequest(const uint32 size) ;
00102 void CleanupParam(bool deallocate = false);
00103
00104
00105 void Abort()
00106 {
00107 Cancel();
00108 }
00109
00110 void RequestDone()
00111 {
00112 iContainer.Abort();
00113 }
00114
00115 inline int GetSocketError();
00116
00117 void DoCancel()
00118 {
00119 SocketI()->CancelFxn(iContainer.iSocketFxn);
00120
00121
00122
00123 }
00124
00125 void Run();
00126
00127 virtual void Success()
00128 {}
00129
00130 OsclSocketMethod& iContainer;
00131 int32 iSocketError;
00132 SocketRequestParam *iParam;
00133 uint32 iParamSize;
00134
00135 OsclSocketI *SocketI()
00136 {
00137 return iContainer.iContainer.iSocket;
00138 }
00139
00140 OsclSocketObserver* SocketObserver()
00141 {
00142 return iContainer.iContainer.iObserver;
00143 }
00144 uint32 Id()
00145 {
00146 return iContainer.iContainer.iId;
00147 }
00148 Oscl_DefAlloc& Alloc()
00149 {
00150 return iContainer.iContainer.Alloc();
00151 }
00152
00153 friend class OsclSocketI;
00154 friend class OsclSocketMethod;
00155 friend class OsclSocketRequest;
00156 };
00157
00158 inline void OsclSocketMethod::AbortAll()
00159 {
00160 Abort();
00161 if (iSocketRequestAO)
00162 iSocketRequestAO->Abort();
00163 }
00164
00165 inline void OsclSocketMethod::CancelMethod()
00166 {
00167
00168 Abort();
00169
00170 iSocketRequestAO->DoCancel();
00171 }
00172
00173 inline void OsclSocketMethod::MethodDone()
00174 {
00175 iSocketRequestAO->Abort();
00176 }
00177
00178 #endif
00179