javaextensions/wma/sms_cbs/src/smsconnection.h
branchRCL_3
changeset 19 04becd199f91
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     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 
       
    19 #ifndef SMSCONNECTION_H
       
    20 #define SMSCONNECTION_H
       
    21 
       
    22 #include <jni.h>
       
    23 #include <errno.h>
       
    24 #include "monitor.h"
       
    25 #include "connectionlistener.h"
       
    26 #include "serverconnectionbase.h"
       
    27 #include "smsplatformservice.h"
       
    28 #include "serverconnectionfactory.h"
       
    29 
       
    30 namespace java
       
    31 {
       
    32 namespace wma
       
    33 {
       
    34 
       
    35 /**
       
    36  *  CJavaSmsConnection implements  ConnectionListener.
       
    37  *  It offers methods for sending , to get
       
    38  *  number of data segments to send the message and to
       
    39  *  receive the message.
       
    40  *  @lib
       
    41  *  @
       
    42  */
       
    43 
       
    44 class SmsConnection: public java::push::ConnectionListener
       
    45 {
       
    46 public:
       
    47     //Constructor
       
    48     SmsConnection(std::wstring aUri, bool aServerConnection);
       
    49 
       
    50     void initialize();
       
    51     /**
       
    52      * Method to send the message.
       
    53      * @return int The success or Failure value.
       
    54      */
       
    55 
       
    56     int send();
       
    57     /**
       
    58      * Method to close the connection.
       
    59      *
       
    60      */
       
    61 
       
    62     void close();
       
    63     /**
       
    64      * from ConnectionListener.
       
    65      * This function is called when a Message arrives.
       
    66      * This function notify's the other thread which inturn notifies the
       
    67      * java side.
       
    68      */
       
    69 
       
    70     void msgArrived(const std::wstring&);
       
    71     /**
       
    72      * from ConnectionListener.
       
    73      * This function is called when a error occurred while receiving
       
    74      * the message.This function notify's the other thread which inturn
       
    75      * notifies the java side, about the error.
       
    76      * @param[in] aUri - Uri of the opened connection.
       
    77      * @param[in] aErrCode - error code.
       
    78      * @param[in] aErrText - error text.
       
    79      */
       
    80     void error(const std::wstring& aUri, int aErrCode,
       
    81                const std::string& aErrText);
       
    82     /**
       
    83      * Gets the Message type of the received Message
       
    84      * @return int The type of the Message either Binary/Text Message.
       
    85      */
       
    86 
       
    87     int getMessageType();
       
    88     /**
       
    89      * Gets the Time stamp of the received message.
       
    90      * @return jlong The time value as jlong.
       
    91      */
       
    92 
       
    93     jlong getTimestamp();
       
    94 
       
    95     //Destructor
       
    96     ~SmsConnection();
       
    97     /**
       
    98      * checks for any missed messages while opening a connection.
       
    99      * waits for incoming message & notifies the java side.
       
   100      * @param[in] aJni Jni interface pointer
       
   101      * @param[in] apeer jobject
       
   102      */
       
   103 
       
   104     void open(JNIEnv& aJni, jobject aPeer);
       
   105     /**
       
   106      * gets the received message as jobject to java side.
       
   107      * @param[in] aJni  Jni interface pointer.
       
   108      * @param[in] aMsgType Message type of the received message.
       
   109      * @return jobject The received message as jobject.
       
   110      */
       
   111 
       
   112     jobject getData(JNIEnv& aJni, const int aMsgType);
       
   113     /**
       
   114      * Gets the Remote Host Address.
       
   115      * @param[in] aJni  Jni interface pointer.
       
   116      * @return jstring The RemoteHostAddress as jstring.
       
   117      */
       
   118 
       
   119     jstring getRemoteHostAddress(JNIEnv& aJni);
       
   120 
       
   121     /**
       
   122      * function that calculates and returns numberofDataSegments of the Message.
       
   123      * @param[in]  atype  MessageType
       
   124      * @param[in] aLength length of the message
       
   125      * @param[in] aport port number
       
   126      * @param[in] ahostaddress Destination address
       
   127      * @param[in] adata Message data
       
   128      * @return int number of data segments.
       
   129      */
       
   130 
       
   131     int numberOfDataSegments(const int atype, const int aLenght, const int aport,
       
   132                              const char* ahostaddress, const char* adata);
       
   133 
       
   134 private:
       
   135     //Any error while receiving
       
   136     int mError;
       
   137     //Uri of the opening connection.
       
   138     std::wstring mUri;
       
   139     //Number of Messages on queue
       
   140     int mMessagesOnQueue;
       
   141     //flag to identify server/client connection
       
   142     bool mServerConnection;
       
   143     //flag to notify notifier thread whether to exit or to listen
       
   144     bool mReceiveOperation;
       
   145     //own server connection
       
   146     ServerConnectionBase* mServerConn;
       
   147     //own os agnostic CSmsPlatformService
       
   148     SmsPlatformService* mMsgConn;
       
   149     // own monitor object
       
   150     java::util::Monitor* mMessageMonitor;
       
   151     //own server connection factory object
       
   152     java::push::ServerConnectionFactory* mServerConnectionFactory;
       
   153 };
       
   154 
       
   155 } //namespace wma
       
   156 } //namespace java
       
   157 #endif // SMSCONNECTION_H