up_poster_epoc.hpp

Go to the documentation of this file.
00001 /*
00002  !concept {:name => "Multipart HTTP posting",
00003    :desc => "Multipart HTTP(S) POSTing using the Symbian HTTP client API."}
00004 */
00005 
00006 #ifndef __up_poster_epoc_hpp__
00007 #define __up_poster_epoc_hpp__
00008 
00009 #include "application_config.h"
00010 
00011 #if __FEATURE_UPLOADER__
00012 
00013 #include "utils_cl2.h"
00014 
00015 #include "common/epoc_rs_buf8.hpp"
00016 
00017 #include <e32base.h>
00018 #include <es_sock.h>
00019 #include <http.h>
00020 #include <s32file.h>
00021 
00022 class MDataSupplier :
00023   public MHTTPDataSupplier
00024 {
00025 public:
00026   virtual void SetHttpTransaction(RHTTPTransaction* aTransaction) = 0;
00027 };
00028 
00029 #define KMultiPartBoundaryMaxLen 48
00030 
00031 NONSHARABLE_CLASS(CFileDataSupplier) :
00032   public CBase, public MDataSupplier
00033 {
00034  public:
00035   virtual ~CFileDataSupplier();
00036   void OpenL(const TDesC& aFileName);
00037   void Close();
00038   void CloseFile();
00039   const TDesC8& Boundary() const; // at most KMultiPartBoundaryMaxLen bytes
00040  public: // MHTTPDataSupplier
00041   TBool GetNextDataPart(TPtrC8& aDataPart); // May leave!
00042   void ReleaseData(); // May leave!
00043   TInt Reset();
00044   TInt OverallDataSize();
00045  public: // MDataSupplier
00046   void SetHttpTransaction(RHTTPTransaction* aTransaction) 
00047   { 
00048     iTransaction = aTransaction; 
00049   }
00050  private: // property
00051   TFileName iFileName;
00052   DEF_SESSION(RFs, iFs);
00053   DEF_SESSION(RFile, iFile);
00054   RRsBuf8 iPrelude;
00055   RRsBuf8 iEpilogue;
00056   TBuf8<512> iBuffer;
00057   TInt iDataLen;
00058   TInt iPhase; // 0 = start, 1 = in file content, 2 = file content done (and suffix left)
00059   RHTTPTransaction* iTransaction;
00060 };
00061 
00062 // For the client to receive upload completion notifications.
00063 class MPosterObserver
00064 {
00065 public:
00066   // The error code is either a Symbian error code (if negative), or
00067   // one of those given below.
00068   virtual void PosterEvent(TInt anError) = 0;
00069 };
00070 
00071 #define POSTER_SUCCESS 1
00072 #define POSTER_TRANSIENT_FAILURE 2
00073 #define POSTER_PERMANENT_FAILURE 3
00074 
00075 /***koog 
00076 (require codegen/symbian-cxx)
00077 (ctor-defines/spec
00078  "CPosterAo" ;; name
00079  "MPosterObserver& anObserver, TUint32 aIapId" ;; args
00080  "iObserver(anObserver), iIapId(aIapId)" ;; inits
00081  "" ;; ctor
00082  #t ;; ConstructL
00083 )
00084  ***/
00085 #define CTOR_DECL_CPosterAo  \
00086 public: static CPosterAo* NewLC(MPosterObserver& anObserver, TUint32 aIapId); \
00087 public: static CPosterAo* NewL(MPosterObserver& anObserver, TUint32 aIapId); \
00088 private: CPosterAo(MPosterObserver& anObserver, TUint32 aIapId); \
00089 private: void ConstructL();
00090 
00091 #define CTOR_IMPL_CPosterAo  \
00092 CPosterAo* CPosterAo::NewLC(MPosterObserver& anObserver, TUint32 aIapId) \
00093 { \
00094   CPosterAo* obj = new (ELeave) CPosterAo(anObserver, aIapId); \
00095   CleanupStack::PushL(obj); \
00096   obj->ConstructL(); \
00097   return obj; \
00098 } \
00099  \
00100 CPosterAo* CPosterAo::NewL(MPosterObserver& anObserver, TUint32 aIapId) \
00101 { \
00102   CPosterAo* obj = CPosterAo::NewLC(anObserver, aIapId); \
00103   CleanupStack::Pop(obj); \
00104   return obj; \
00105 } \
00106  \
00107 CPosterAo::CPosterAo(MPosterObserver& anObserver, TUint32 aIapId) : iObserver(anObserver), iIapId(aIapId) \
00108 {}
00109 /***end***/
00110 
00111 NONSHARABLE_CLASS(CPosterAo) : 
00112   public CBase,
00113   public MHTTPTransactionCallback
00114 {
00115   CTOR_DECL_CPosterAo;
00116 
00117  private: // property
00118   enum TState { EReady = 0, EActive, EDone };
00119   TState iState;
00120 
00121   MPosterObserver& iObserver;
00122   TUint32 iIapId;
00123 
00124   DEF_SESSION(RSocketServ, iSocketServ);
00125   DEF_SESSION(RConnection, iConnection);
00126   DEF_SESSION(RHTTPSession, iHttpSession);
00127   DEF_SESSION(RHTTPTransaction, iHttpTransaction); // closed with iHttpSession also
00128   TInt iHttpStatus;
00129 
00130   CFileDataSupplier* iFileDataSupplier;
00131 
00132   TBuf8<KMultiPartBoundaryMaxLen> iBoundary;
00133 
00134  public:
00135   ~CPosterAo();
00136   
00137   // Asynchronous method.
00138   void PostFileL(const TDesC8& aUri,
00139      const TDesC& aFileName);
00140 
00141   TBool IsActive() const { return iState == EActive; }
00142 
00143  private: // MHTTPTransactionCallback
00144   void MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent);
00145   TInt MHFRunError(TInt aError,
00146        RHTTPTransaction aTransaction,
00147        const THTTPEvent& aEvent);
00148   
00149  private: // internal methods
00150   void PostComplete(TInt errCode);
00151 
00152   void SetHeaderL(RHTTPHeaders aHeaders,
00153       TInt aHdrField,
00154       const TDesC8& aHdrValue);
00155 
00156   void SetBoundary(const TDesC8& aBoundary) { iBoundary = aBoundary; }
00157   
00158   // Asynchronous method.
00159   void PostGenericL(const TDesC8& aUri,
00160         MDataSupplier& aDataSupplier);
00161 
00162 };
00163 
00164 #endif // __FEATURE_UPLOADER__
00165 
00166 #endif /* __up_poster_epoc_hpp__ */
00167 
00168 /**
00169 
00170 up_poster_epoc.hpp
00171 
00172 Copyright 2009 Helsinki Institute for Information Technology (HIIT)
00173 and the authors. All rights reserved.
00174 
00175 Authors: Tero Hasu <tero.hasu@hut.fi>
00176 
00177 Permission is hereby granted, free of charge, to any person
00178 obtaining a copy of this software and associated documentation files
00179 (the "Software"), to deal in the Software without restriction,
00180 including without limitation the rights to use, copy, modify, merge,
00181 publish, distribute, sublicense, and/or sell copies of the Software,
00182 and to permit persons to whom the Software is furnished to do so,
00183 subject to the following conditions:
00184 
00185 The above copyright notice and this permission notice shall be
00186 included in all copies or substantial portions of the Software.
00187 
00188 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00189 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00190 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00191 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
00192 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
00193 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00194 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
00195 SOFTWARE.
00196 
00197  **/

ContextLogger2—ContextLogger2 Logger Daemon Internals—Generated on Mon May 2 13:49:56 2011 by Doxygen 1.6.1