hti/PC_Tools/DataGateway/INC/datagateway.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 the headers of DataGatewaySocketWriterThread,
       
    16 *	DataGatewaySocketReaderThread, DataGatewayClientThread and DataGateway
       
    17 *	classes.
       
    18 */
       
    19 
       
    20 #ifndef DATAGATEWAY_H
       
    21 #define DATAGATEWAY_H
       
    22 
       
    23 #pragma warning ( disable : 4786 )
       
    24 
       
    25 #include "Socket.h"
       
    26 
       
    27 #include <windows.h>
       
    28 #include <process.h>
       
    29 
       
    30 #include "util.h"
       
    31 #include "common.h"
       
    32 #include "plugin.h"
       
    33 #include "safequeue.h"
       
    34 #include "thread.h"
       
    35 
       
    36 const int g_DataGatewayDefaultTcpIpPort       = 2000;
       
    37 const int g_DataGatewayDefaultTcpIpBufferSize = 8 * 1024;
       
    38 
       
    39 // Maximum time to wait
       
    40 extern long g_MaximumShutdownWaitTime;
       
    41 
       
    42 extern DWORD g_ErrorCode;
       
    43 
       
    44 //**********************************************************************************
       
    45 // Class DataGatewaySocketWriterThread
       
    46 //
       
    47 // This thread is used to read Data from outgoing queue 
       
    48 // and write it to Socket(connected to program using DataGateway)
       
    49 //**********************************************************************************
       
    50 
       
    51 class DataGatewaySocketWriterThread : public Thread<DataGatewaySocketWriterThread>
       
    52 {
       
    53 public:
       
    54 	DataGatewaySocketWriterThread(SafeQueue<Data*>* q, Socket* s);
       
    55 	/*
       
    56 	 * Main loop of thread
       
    57 	 * Reads Data from outgoing queue and writes it to Socket(connected to program using DataGateway)
       
    58 	 */
       
    59 	void Run();
       
    60 	void Stop();
       
    61 	bool IsRunning();
       
    62 
       
    63 private:
       
    64 	//outgoing queue
       
    65 	SafeQueue<Data*>* m_Queue;
       
    66 	//socket to which software using DataGateway is connected to
       
    67 	Socket* m_Socket;
       
    68 	bool m_Running;
       
    69 };
       
    70 
       
    71 //**********************************************************************************
       
    72 // Class DataGatewaySocketReaderThread
       
    73 //
       
    74 // This thread is used to read incoming bytes from Socket(connected to program using DataGateway)
       
    75 // which it then encapsulates into Data objects and forwards to outgoing queue
       
    76 //**********************************************************************************
       
    77 
       
    78 class DataGatewaySocketReaderThread : public Thread<DataGatewaySocketReaderThread>
       
    79 {
       
    80 public:
       
    81 	DataGatewaySocketReaderThread(SafeQueue<Data*>* q, long bufsize, Socket* s);
       
    82 	/*
       
    83 	 * Main loop of thread
       
    84 	 * Reads bytes from Socket(connected to program using DataGateway), encapsulates them to Data object and puts these to outgoing queue
       
    85 	 */
       
    86 	void Run();
       
    87 	void Stop();
       
    88 	bool IsRunning();
       
    89 
       
    90 private:
       
    91 	//incoming queue
       
    92 	SafeQueue<Data*>* m_Queue;
       
    93 	//socket to which software using DataGateway is connected to
       
    94 	Socket* m_Socket;
       
    95 	bool m_Running;
       
    96 	long m_TcpIpBufferSize;
       
    97 };
       
    98 
       
    99 //**********************************************************************************
       
   100 // Class DataGatewayClientThread
       
   101 //
       
   102 // This thread serves DataGateway's clients
       
   103 // Gets Data from incoming queue to which DataGatewaySocketReader has pushed it and forwards
       
   104 // them to CommChannelPlugin.
       
   105 // The thread also reads incoming data from CommChannelPlugin and forwards them to outgoing queue which
       
   106 // DataGatewaySocketWriter then reads
       
   107 //**********************************************************************************
       
   108 
       
   109 class DataGatewayClientThread : public Thread<DataGatewayClientThread>
       
   110 {
       
   111 public:
       
   112 	DataGatewayClientThread(Socket** s, long bufsize, const string& commchannel);
       
   113 	DataGatewayClientThread(Socket** s, long bufsize, CommChannelPlugin** f);
       
   114 	~DataGatewayClientThread();
       
   115 	/*
       
   116 	 * Main loop of thread
       
   117 	 * Gets Data from incoming queue to which DataGatewaySocketReader has pushed it and forwards
       
   118 	 * them to CommChannelPlugin.
       
   119 	 * Reads incoming data from CommChannelPlugin and forwards them to outgoing queue which
       
   120 	 * DataGatewaySocketWriter then reads
       
   121 	 */
       
   122 	void Run();
       
   123 	void Stop();
       
   124 
       
   125 private:
       
   126 	//incoming queue
       
   127 	SafeQueue<Data*> m_ReaderQueue;
       
   128 	//outgoing queue
       
   129 	SafeQueue<Data*> m_WriterQueue;
       
   130 	//used to read data from socket to incoming queue
       
   131 	DataGatewaySocketReaderThread m_ReaderThread;
       
   132 	//used to write data from outgoing queue to socket
       
   133 	DataGatewaySocketWriterThread m_WriterThread;
       
   134 	//Socket to which software using DataGateway is connected to
       
   135 	Socket** m_Socket;
       
   136 	//The CommChannelPlugin that is used in communication
       
   137 	CommChannelPlugin* m_CommChannelPlugin;
       
   138 	//determines which CommChannelPlugin is loaded
       
   139 	const string& m_CommChannelPluginName;
       
   140 	bool m_Running;
       
   141 	//This value states whether or not Communication Channel Plugin uses late initialization
       
   142 	bool m_CCLateInit;
       
   143 	//This value tells the buffer size that is used
       
   144 	long m_TcpIpBufferSize;
       
   145 };
       
   146 
       
   147 //**********************************************************************************
       
   148 // Class DataGateway
       
   149 //
       
   150 // This is the main thread of DataGateway
       
   151 //**********************************************************************************
       
   152 
       
   153 class DataGateway : public Thread<DataGateway>
       
   154 {
       
   155 public:
       
   156 	DataGateway(int port = g_DataGatewayDefaultTcpIpPort,
       
   157 		        long bufsize = g_DataGatewayDefaultTcpIpBufferSize,
       
   158 				const string& commchannel = "",
       
   159 				bool stayalive = false,
       
   160 				bool cclateinit = false);
       
   161 	void Run();
       
   162 	void Stop();
       
   163 	bool IsRunning();
       
   164 
       
   165 private:
       
   166 	//determines which CommChannelPlugin is loaded
       
   167 	const string& m_CommChannelPluginName;
       
   168 	//reference to CommChannelPlugin
       
   169 	CommChannelPlugin* m_CommChannelPlugin;
       
   170 	Event m_ShutdownEvent;
       
   171 	bool m_Running;
       
   172 	//tells whether DataGateway should stay alive after first client has disconnected
       
   173 	bool m_StayAlive;
       
   174 	//this value states whether or not Communication Channel Plugin uses late initialization
       
   175 	bool m_CCLateInit;
       
   176 	//the port which DataGateway listens for incoming connections
       
   177     int m_TcpIpPort;
       
   178 	//buffer size used in communication
       
   179     long m_TcpIpBufferSize;
       
   180 };
       
   181 
       
   182 #endif
       
   183 
       
   184 // End of the file