Main Page Modules Class Hierarchy Data Structures File List Data Fields Globals Related Pages

# oscl_socket_method.h

Go to the documentation of this file.

    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 //#include "oscl_socket_serv_imp.h"
    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         TPVSocketEvent ThreadLogon();
    00058         TPVSocketEvent ThreadLogoff();
    00059     protected:
    00060         void ConstructL(OsclSocketRequestAO *aAO)
    00061         {
    00062             if (!aAO)
    00063                 OsclError::Leave(OsclErrGeneral);
    00064             iSocketRequestAO = aAO;
    00065         }
    00066
    00067         bool StartMethod(int32 aTimeoutMsec);
    00068
    00069         inline void MethodDone();
    00070
    00071         void Run();
    00072
    00073         OsclSocketRequestAO *iSocketRequestAO;
    00074 };
    00075
    00076 #include "oscl_socket_imp.h"
    00077
    00082 class OsclSocketRequestAO : public OsclActiveObject
    00083 {
    00084     public:
    00085         void ConstructL()
    00086         {
    00087         }
    00088     protected:
    00089
    00090         OsclSocketRequestAO(OsclSocketMethod& aContainer, const char *name)
    00091                 : OsclActiveObject(PV_SOCKET_REQUEST_AO_PRIORITY, name)
    00092                 , iContainer(aContainer)
    00093                 , iSocketError(0)
    00094                 , iParam(NULL)
    00095                 , iParamSize(0)
    00096         {}
    00097
    00098         virtual ~OsclSocketRequestAO()
    00099         {
    00100             CleanupParam(true);
    00101         }
    00102
    00103         OsclAny* NewRequest(const uint32 size) ;
    00104         void CleanupParam(bool deallocate = false);
    00105
    00106
    00107         void Abort()
    00108         {
    00109             Cancel();
    00110         }
    00111
    00112         void RequestDone()
    00113         {
    00114             iContainer.Abort();
    00115         }
    00116
    00117         inline int GetSocketError();
    00118
    00119         void DoCancel()
    00120         {
    00121             SocketI()->CancelFxn(iContainer.iSocketFxn);
    00122             //we launch the cancellation process here.  oscl scheduler
    00123             //will wait on completion of this AO request, which will
    00124             //happen in the server thread.
    00125         }
    00126
    00127         void Run();
    00128
    00129         virtual void Success()
    00130         {}
    00131
    00132         OsclSocketMethod& iContainer;
    00133         int32 iSocketError;
    00134         SocketRequestParam *iParam;
    00135         uint32 iParamSize;
    00136
    00137         OsclSocketI *SocketI()
    00138         {
    00139             return iContainer.iContainer.iSocket;
    00140         }
    00141
    00142         OsclSocketObserver* SocketObserver()
    00143         {
    00144             return iContainer.iContainer.iObserver;
    00145         }
    00146         uint32 Id()
    00147         {
    00148             return iContainer.iContainer.iId;
    00149         }
    00150         Oscl_DefAlloc& Alloc()
    00151         {
    00152             return iContainer.iContainer.Alloc();
    00153         }
    00154
    00155         friend class OsclSocketI;
    00156         friend class OsclSocketMethod;
    00157         friend class OsclSocketRequest;
    00158 };
    00159
    00160 inline void OsclSocketMethod::AbortAll()
    00161 {
    00162     Abort();
    00163     if (iSocketRequestAO)
    00164         iSocketRequestAO->Abort();
    00165 }
    00166
    00167 inline void OsclSocketMethod::CancelMethod()
    00168 {
    00169     //cancel the timeout if any
    00170     Abort();
    00171     //cancel the request to the socket server.
    00172     if (iSocketRequestAO)
    00173         iSocketRequestAO->DoCancel();
    00174 }
    00175
    00176 inline void OsclSocketMethod::MethodDone()
    00177 {
    00178     if (iSocketRequestAO)
    00179         iSocketRequestAO->Abort();
    00180 }
    00181
    00182 #endif
    00183