javaextensions/wma/mms/pushplugin/src.s60/s60mmsserverconnection.h
changeset 21 2a9601315dfc
child 78 71ad690e91f5
equal deleted inserted replaced
18:e8e63152f320 21:2a9601315dfc
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15  *
       
    16 */
       
    17 
       
    18 #ifndef S60MMSSERVERCONNECTION_H
       
    19 #define S60MMSSERVERCONNECTION_H
       
    20 
       
    21 #include <mmsclient.h>
       
    22 #include <mmsapplicationadapter.h>
       
    23 
       
    24 #include "monitor.h"
       
    25 #include "mmsserverconnection.h"
       
    26 
       
    27 using namespace java::push;
       
    28 
       
    29 namespace java
       
    30 {
       
    31 namespace wma
       
    32 {
       
    33 /**
       
    34  *  MmsServerConnection implement  ServerConnectionBase.
       
    35  *  It is responsible to start the midlet when the message arrive in the device
       
    36  *  for a registered midlet  when the midlet is not running.It is also
       
    37  *  responsible to receive message when the midlet is running
       
    38  *  @lib mmsserverconnection.dll
       
    39  *  @
       
    40  */
       
    41 class S60MmsServerConnection: public CActive,
       
    42         public MmsServerConnection,
       
    43         public MMsvSessionObserver,
       
    44         public MMsvEntryObserver
       
    45 {
       
    46 
       
    47 public:
       
    48     //Constructor
       
    49     OS_IMPORT S60MmsServerConnection(const std::wstring& aUri,
       
    50                                      const std::wstring& aFilter);
       
    51     OS_IMPORT virtual ~S60MmsServerConnection();
       
    52     /**
       
    53      * from ServerConnection
       
    54      * Opens the connection. It registers the push URI to the mms engine for
       
    55      * any incoming mms  message on this AppId.
       
    56      * Throws COMMON_SRV_CONN_PLUGIN_ERROR exception if there is an error while
       
    57      * registering the connection.
       
    58      * @param aListener: Listener to be notified when message arrives.
       
    59      *
       
    60      * @return
       
    61      */
       
    62     OS_IMPORT virtual void open(ConnectionListener* aListener);
       
    63     /**
       
    64      *from ServerConnection
       
    65      * Closes the connection
       
    66      * @return
       
    67      */
       
    68     OS_IMPORT virtual void close();
       
    69     /**
       
    70      * from ServerConnection
       
    71      * Return the push register URI
       
    72      * @return std::wstring
       
    73      */
       
    74     OS_IMPORT virtual std::wstring getUri() const;
       
    75     /**
       
    76      * from ServerConnection
       
    77      * sets the filter string
       
    78      * @ aFilter - filter string
       
    79      */
       
    80     OS_IMPORT virtual void setFilter(const std::wstring& aFilter);
       
    81     /**
       
    82      * from ServerConnection
       
    83      * Return the filter string
       
    84      * @return std::wstring the filter string
       
    85      */
       
    86     OS_IMPORT virtual std::wstring getFilter() const;
       
    87     /**
       
    88      * SetOpen()
       
    89      * It is used to Distinguish whether Open is called from Midlet context
       
    90      * or Push Controller .This function is called first when the server
       
    91      * connection is called from MIDlet context.
       
    92      * @return
       
    93      */
       
    94     OS_IMPORT void setOpen();
       
    95 private:
       
    96     //Constructor
       
    97     S60MmsServerConnection();
       
    98     void InitializeL();
       
    99     void MmsRequestCompleted();
       
   100 
       
   101     /**
       
   102      * Check that if the received MMS is valid message
       
   103      * If the message is valid Push launch the midlet.
       
   104      * @param aMsvId: Id of the received message
       
   105      *
       
   106      * @return .
       
   107      */
       
   108     void CheckForValidMessageAndPushL(TMsvId aMsgId);
       
   109     /**
       
   110      * Check that if the received MMS is ready to read
       
   111      *
       
   112      * @param aMsvId: Id of the received message
       
   113      *
       
   114      * @return positive TInt if the message is ready to read otherwise zero.
       
   115      */
       
   116     TBool IsMmsReadyToReadL(TMsvId aMsvId);
       
   117     /**
       
   118      *
       
   119      * thread function.
       
   120      * @
       
   121      * @param :
       
   122      *
       
   123      * @return
       
   124      */
       
   125     static int listenThread(S60MmsServerConnection* aServerConnection);
       
   126     /**
       
   127      * HandleSessionEventL from MMsvSessionObserver
       
   128      * We are not handling any thing in this method.
       
   129      * @
       
   130      * @param aEvent:
       
   131      * @param aArg1:
       
   132      * @param aArg2:
       
   133      * @param aArg3:
       
   134      *
       
   135      * @return
       
   136      */
       
   137     void HandleSessionEventL(TMsvSessionEvent aEvent,TAny* aArg1,
       
   138                              TAny* aArg2,
       
   139                              TAny* aArg3);
       
   140     /**
       
   141      * HandleEntryEventL
       
   142      * From MMsvEntryObserver
       
   143      * @
       
   144      * @param aEvent: TMsv entry event
       
   145      * @param aArg1:
       
   146      * @param aArg2:
       
   147      * @param aArg3:
       
   148      *
       
   149      * @return
       
   150      */
       
   151     void HandleEntryEventL(TMsvEntryEvent aEvent, TAny* aArg1,
       
   152                            TAny* aArg2,
       
   153                            TAny* aArg3);
       
   154 private: // from CActive
       
   155     void DoCancel();
       
   156     void RunL();
       
   157     TInt RunError(TInt aError);
       
   158 
       
   159 protected:
       
   160     enum TOperation
       
   161     {
       
   162         EReceivingMessageForNotify,
       
   163         EReceivingMessageForListen,
       
   164         ENotifyingReadMessageSucceeded,
       
   165         ENotifyingClose,
       
   166     };
       
   167 
       
   168     int mError;
       
   169     //thread id
       
   170     RThread mThread;
       
   171     // Uri of the push connection
       
   172     std::wstring mUri;
       
   173     // the ongoing operation which is executed by the server connection object.
       
   174     TOperation mState;
       
   175     // Apllication id
       
   176     std::wstring mAppId;
       
   177     //defines the acceptable remote host.
       
   178     std::wstring mFilter;
       
   179     CMsvSession* mSession;
       
   180     // Application ID
       
   181     HBufC* mApplicationId;
       
   182     // flag to indicate connection is active or not, useful during close.
       
   183     bool mActiveConnection;
       
   184     // To synchronize threads
       
   185     pthread_mutex_t  mMutex;
       
   186     pthread_cond_t   mCondVar;
       
   187     CMsvEntry* mClientEntry;
       
   188     // flag to indicate listening by push or application
       
   189     bool mIsAppLaunched;
       
   190     //listener to be notified for incoming messages
       
   191     ConnectionListener* mListener;
       
   192     // handle to monitor object
       
   193     java::util::Monitor* mOpenMonitor;
       
   194     // reference to application adapter
       
   195     CMmsApplicationAdapter* mMmsApplicationAdapter;
       
   196 };
       
   197 
       
   198 }//end of namespace wma
       
   199 }//end of namespace java
       
   200 
       
   201 #endif // S60MMSSERVERCONNECTION_H