Debian Codegraph @

gobi-api/Gobi_2012-06-18-1054/Core/Socket.h

raw
1 /*===========================================================================
2 FILE:
3 Socket.h
4
5 DESCRIPTION:
6 Declaration of cSocket class
7
8 PUBLIC CLASSES AND METHODS:
9 cSocket
10 This class wraps low level communication to qmuxd
11
12 Copyright (c) 2012, Code Aurora Forum. All rights reserved.
13
14 Redistribution and use in source and binary forms, with or without
15 modification, are permitted provided that the following conditions are met:
16 * Redistributions of source code must retain the above copyright
17 notice, this list of conditions and the following disclaimer.
18 * Redistributions in binary form must reproduce the above copyright
19 notice, this list of conditions and the following disclaimer in the
20 documentation and/or other materials provided with the distribution.
21 * Neither the name of Code Aurora Forum nor
22 the names of its contributors may be used to endorse or promote
23 products derived from this software without specific prior written
24 permission.
25
26
27 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
31 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 POSSIBILITY OF SUCH DAMAGE.
38 ===========================================================================*/
39
40 //---------------------------------------------------------------------------
41 // Include Files
42 //---------------------------------------------------------------------------
43 #include "Event.h"
44 #include "Connection.h"
45
46 //---------------------------------------------------------------------------
47 // Pragmas
48 //---------------------------------------------------------------------------
49 #pragma once
50
51 /*=========================================================================*/
52 // Enum eQMUXDMessageTypes
53 // Types to be passed into SendCtl() for cSocket
54 /*=========================================================================*/
55 enum eQMUXDMessageTypes
56 {
57 eQMUXD_MSG_WRITE_QMI_SDU = 0,
58 eQMUXD_MSG_ALLOC_QMI_CLIENT_ID = 1,
59 eQMUXD_MSG_RELEASE_QMI_CLIENT_ID = 2,
60 };
61
62 /*=========================================================================*/
63 // Class cSocket
64 /*=========================================================================*/
65 class cSocket : public cConnection
66 {
67 public:
68 // Constructor
69 cSocket();
70
71 // Destructor
72 ~cSocket();
73
74 // Is this object valid?
75 bool IsValid();
76
77 // Connect to the specified channel
78 bool Connect( LPCSTR pChannel );
79
80 // Run an IOCTL on the open file handle
81 int SendCtl(
82 UINT ioctlReq,
83 void * pData );
84
85 // Disconnect from the current port
86 bool Disconnect();
87
88 // Configure the port with the passed in parameters
89 bool ConfigureSettings( termios * pSettings );
90
91 // Return the current port settings
92 bool GetSettings( termios * pSettings );
93
94 // Cancel any in-progress I/O
95 bool CancelIO();
96
97 // Cancel any in-progress receive operation
98 bool CancelRx();
99
100 // Cancel any in-progress transmit operation
101 bool CancelTx();
102
103 // Receive data
104 bool RxData(
105 BYTE * pBuf,
106 ULONG bufSz,
107 cIOCallback * pCallback );
108
109 // Transmit data
110 bool TxData(
111 const BYTE * pBuf,
112 ULONG bufSz );
113
114 // (Inline) Return current channel ID
115 int GetChannelID() const
116 {
117 return mChannelID;
118 };
119
120 // Are we currently connected to a port?
121 bool IsConnected()
122 {
123 return (mSocket != INVALID_HANDLE_VALUE);
124 };
125
126 protected:
127
128 /* Handle to socket */
129 int mSocket;
130
131 // Cancel the write request?
132 bool mbCancelWrite;
133
134 /* Buffer */
135 BYTE * mpBuffer;
136
137 /* Buffer size */
138 ULONG mBuffSz;
139
140 /* Pipe for comunication with thread */
141 int mCommandPipe[2];
142
143 /* Thread ID of Rx Thread. */
144 pthread_t mRxThreadID;
145
146 /* Control message completion event */
147 cEvent mCtrlMsgComplete;
148
149 /* QMUXD client ID */
150 int mQMUXDClientID;
151
152 /* QMUX client and service IDs */
153 int mQMUXClientID;
154 int mQMUXServiceID;
155
156 /* SMD Channel ID. 0 = SMD_DATA_5 */
157 int mChannelID;
158
159 /* The SMD transaction ID */
160 int mQMUXDTxID;
161
162 // Rx thread is allowed complete access
163 friend void * RxSocketThread( void * pData );
164 };