hti/PC_Tools/HTIGateway/HtiGateway/inc/SOAPHandler.h
branchRCL_3
changeset 59 8ad140f3dd41
parent 0 a03f92240627
equal deleted inserted replaced
49:7fdc9a71d314 59:8ad140f3dd41
       
     1 /*
       
     2 * Copyright (c) 2009 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 *   This file contains header of SOAPHandler class
       
    16 */
       
    17 
       
    18 #ifndef __SOAP__HANDLER_H_
       
    19 #define __SOAP__HANDLER_H_
       
    20 
       
    21 #include "thread.h"
       
    22 #include "HtiSoapHandlerInterface.h"
       
    23 #include "HtiPluginDll.h"
       
    24 
       
    25 #include <string>
       
    26 
       
    27 using namespace std;
       
    28 
       
    29 #define LOOP_WAIT_INTERVAL INFINITE //in ms
       
    30 #define LOOP_CHECK_INTERVAL 100 //in ms
       
    31 
       
    32 //forward decl.
       
    33 class HtiDispatcher;
       
    34 class HtiMessage;
       
    35 
       
    36 //**********************************************************************************
       
    37 // Class SOAPHandler
       
    38 //
       
    39 // This class is used to handle SOAP requests, send HtiMessages 
       
    40 // and handle HTI responses by using loaded HtiPluginDll
       
    41 //**********************************************************************************
       
    42 class SoapHandler: public Thread<SoapHandler>, public HtiSoapHandlerInterface
       
    43 {
       
    44 public:
       
    45 	SoapHandler(const string& pluginName);
       
    46 	virtual ~SoapHandler();
       
    47 
       
    48 	inline void SetDispatcher( HtiDispatcher* dispatcher);
       
    49 
       
    50 	/**
       
    51 	 * This method is used to init HtiPluginDll
       
    52 	 */
       
    53 	bool LoadPlugin();
       
    54 
       
    55 	inline char* soapAction(){return m_HtiPlugin->soapActionName();};
       
    56 	inline int serviceUID(){return m_HtiPlugin->serviceUID();};
       
    57 
       
    58 	/**
       
    59 	* Just a wrapper around soap_serve() created by gSOAP
       
    60 	* called by DataGatewaySOAPServerThread for a new SOAP request
       
    61 	* return true if request can be processed
       
    62 	*/
       
    63 	bool ServeSoap(struct soap* soapEnv);
       
    64 
       
    65 	/**
       
    66 	* Actual SOAP request processing in the thread
       
    67 	* if it was accepted in ServeSoap()
       
    68 	* The request is processed using HtiPluginDll
       
    69 	*/
       
    70 	void DoServeSoap();
       
    71 
       
    72 	/**
       
    73 	 * This method tells whether or not this handler is currently busy processing request
       
    74 	 */
       
    75 	bool IsBusyForSoapRequest();
       
    76 
       
    77 	/**
       
    78 	 * This method tells whether or not this handler is currently busy processing hti message
       
    79 	 */
       
    80 	bool IsBusyForHtiMessage();
       
    81 	
       
    82 	/*
       
    83 	 * This method is used to check if SoapHandler is currently waiting for Hti Message
       
    84 	 */
       
    85 	bool IsWaitsForHtiMessage();
       
    86 
       
    87 	/**
       
    88 	* Notification function called when handler receive
       
    89 	* new HTI message from Symbian side
       
    90 	*/
       
    91 	void ProcessHtiResponse();
       
    92 	
       
    93 	/**
       
    94 	 * This loop waits until either a SOAP request or HTI response event has arrived
       
    95 	 * When one of them arrives, it is handled and the loop starts again to wait
       
    96 	 * for a new request or response
       
    97 	 */
       
    98 	void Run();
       
    99 	void Stop();
       
   100 
       
   101 	/**
       
   102 	* wait for hti message
       
   103 	* Suspend thread until HtiMessage for the loaded plug-in is received
       
   104 	* Return true if hti message is received or false if timeout
       
   105 	*/ 
       
   106 	bool WaitForHtiMessage( DWORD timeout );
       
   107 	inline bool WaitForHtiMessage( ){return WaitForHtiMessage( INFINITE );};
       
   108 
       
   109 	int ReceivedHtiMessageBodySize();
       
   110 	void* ReceivedHtiMessageBody();
       
   111 
       
   112 	/*
       
   113 	 * HtiPluginDll's call this method
       
   114 	 * It creates a HtiMessage of the data given as parameters and sends it using HtiDispatcher
       
   115 	 */
       
   116 	void SendHtiMessage( DWORD serviceId, void* body, DWORD len );
       
   117 	void SendHtiMessage( DWORD serviceId, void* body, DWORD len, BYTE priority );
       
   118 
       
   119 	//error message
       
   120 	bool IsReceivedHtiError();
       
   121 	int HtiErrorCode();
       
   122 	int HtiServiceErrorCode();
       
   123 	char* HtiServiceErrorDerscription();
       
   124 	void SendSoapFaultFromReceivedHtiError();
       
   125 
       
   126 	/**
       
   127 	 * This method is called when incoming data has been read from CommChannelPlugin
       
   128 	 * The method sets m_hReceiveHtiEvent to signaled state(Run method waits this event object to become signaled)
       
   129 	 */
       
   130 	bool ReceiveHtiMessage(HtiMessage* message);
       
   131 
       
   132 private:
       
   133 
       
   134 	void CleanSoapEnv();
       
   135 
       
   136 // data members
       
   137 protected:
       
   138 	string m_PluginName;
       
   139 
       
   140 	HtiPluginDll* m_HtiPlugin;
       
   141 
       
   142 	HtiDispatcher* m_HtiDispatcher;
       
   143 
       
   144 	/**
       
   145 	* Message passed to the handler by AcceptHtiMessage()
       
   146 	* It is usually processed than 
       
   147 	*/
       
   148 	HtiMessage* m_ReceiveHtiMsg;
       
   149 
       
   150 	bool m_Running;
       
   151 
       
   152 private:
       
   153 	/**
       
   154 	* used to wait for messages from symbian-side
       
   155 	*/
       
   156 	HANDLE m_hReceiveHtiEvent;
       
   157 
       
   158 	/**
       
   159 	* used to wait for SOAP request
       
   160 	*/
       
   161 	HANDLE m_hReceiveSoapEvent;
       
   162 
       
   163 	/**
       
   164 	* Used to allow define either thread is busy
       
   165 	*/
       
   166 	HANDLE m_hHandlerCanAcceptSoapRequest;
       
   167 	HANDLE m_hHandlerCanAcceptHtiMessage;
       
   168 
       
   169 	/**
       
   170 	* Needed to dispatch error messages without tartet service uid
       
   171 	**/
       
   172 	HANDLE m_hHandlerWaitsHtiMessage;
       
   173 
       
   174 	/**
       
   175 	* Local gSOAP env
       
   176 	*/
       
   177 	struct soap* m_SoapEnv;
       
   178 };
       
   179 /*
       
   180 inline HtiMessage* SoapHandler::GetReceivedHtiMessage()
       
   181 {
       
   182 	HtiMessage* r = m_ReceiveHtiMsg;
       
   183 	m_ReceiveHtiMsg = NULL;
       
   184 	return r;
       
   185 }
       
   186 */
       
   187 
       
   188 inline void SoapHandler::SetDispatcher( HtiDispatcher* dispatcher)
       
   189 {
       
   190 	m_HtiDispatcher = dispatcher;
       
   191 }
       
   192 
       
   193 #endif //__SOAP__HANDLER_H_