|
1 /* |
|
2 * Copyright (c) 2005-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 * CSerialTcpRelay |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 #ifndef __CSERIALTCPRELAY_H__ |
|
22 #define __CSERIALTCPRELAY_H__ |
|
23 |
|
24 |
|
25 /************************************************************************************* |
|
26 * |
|
27 * Local Includes |
|
28 * |
|
29 ************************************************************************************/ |
|
30 #include "CSerialPort.h" |
|
31 #include "../ThreadLibrary/CAThread.h" |
|
32 |
|
33 |
|
34 /************************************************************************************* |
|
35 * |
|
36 * Definitions |
|
37 * |
|
38 ************************************************************************************/ |
|
39 #define SERIALREADBUFFSIZE (1024) |
|
40 #define SOCKETREADBUFFSIZE (1024) |
|
41 |
|
42 |
|
43 /************************************************************************************* |
|
44 * |
|
45 * Types |
|
46 * |
|
47 ************************************************************************************/ |
|
48 typedef enum { |
|
49 RE_SUCCESS, |
|
50 RE_SOCKET_FAILED, |
|
51 RE_CONNECT_FAILED, |
|
52 RE_INITIAL_SEND_FAILED |
|
53 } TRelayError; |
|
54 |
|
55 |
|
56 typedef enum { |
|
57 RS_NEW, |
|
58 RS_ACTIVE, |
|
59 RS_CLOSED, |
|
60 } TRelayState; |
|
61 |
|
62 /************************************************************************************* |
|
63 * |
|
64 * CSerialTcpRelay Definition |
|
65 * |
|
66 ************************************************************************************/ |
|
67 class CSerialTcpRelay |
|
68 { |
|
69 public: |
|
70 CSerialTcpRelay(); |
|
71 ~CSerialTcpRelay(); |
|
72 TRelayError InitialiseRelay( CSerialPort *aSerialPort, SOCKADDR_IN aRemoteAddress, char *aInitialBuffer, int aBufferLength, int *aErrCode ); |
|
73 TRelayError ExecuteRelay(); |
|
74 |
|
75 private: |
|
76 TRelayError ExecuteSerialThread(); |
|
77 TRelayError ExecuteSocketThread(); |
|
78 |
|
79 static int SerialThreadProc( CSerialTcpRelay *aRelay ); |
|
80 static int SocketThreadProc( CSerialTcpRelay *aRelay ); |
|
81 |
|
82 CSerialPort *iSerialPort; |
|
83 SOCKET iSocket; |
|
84 SOCKADDR_IN iRemoteAddress; |
|
85 char iSerialReadBuffer[SERIALREADBUFFSIZE]; |
|
86 char iSocketReadBuffer[SOCKETREADBUFFSIZE]; |
|
87 TRelayState iState; |
|
88 TRelayState iSerialState; |
|
89 TRelayState iSocketState; |
|
90 CAThread iSerialThread; |
|
91 CAThread iSocketThread; |
|
92 }; |
|
93 |
|
94 #endif |