1 | /****************************************************************************** |
---|
2 | * QUANTA - A toolkit for High Performance Data Sharing |
---|
3 | * Copyright (C) 2003 Electronic Visualization Laboratory, |
---|
4 | * University of Illinois at Chicago |
---|
5 | * |
---|
6 | * All rights reserved. |
---|
7 | * |
---|
8 | * Redistribution and use in source and binary forms, with or without |
---|
9 | * modification, are permitted provided that the following conditions are met: |
---|
10 | * |
---|
11 | * * Redistributions of source code must retain the above copyright |
---|
12 | * notice, this list of conditions and the following disclaimer. |
---|
13 | * * Redistributions in binary form must reproduce the above |
---|
14 | * copyright notice, this list of conditions and the following disclaimer |
---|
15 | * in the documentation and/or other materials provided with the distribution. |
---|
16 | * * Neither the name of the University of Illinois at Chicago nor |
---|
17 | * the names of its contributors may be used to endorse or promote |
---|
18 | * products derived from this software without specific prior written permission. |
---|
19 | * |
---|
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
---|
23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
---|
24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
---|
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
---|
26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
---|
27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
---|
28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
---|
29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
---|
30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
31 | * |
---|
32 | * Direct questions, comments etc about Quanta to cavern@evl.uic.edu |
---|
33 | *****************************************************************************/ |
---|
34 | |
---|
35 | #ifndef _QUANTAPLUS_PERF_CLIENT |
---|
36 | #define _QUANTAPLUS_PERF_CLIENT |
---|
37 | |
---|
38 | #define PERF_DAEMON_DEFAULT_PORT 9500 |
---|
39 | #define REGISTER_PERF_CLIENT "$$QUANTA_PERF_DAEMON_CLASS$$" |
---|
40 | #define SEND_STAT_CLIENT "$$SEND_STAT_PERF_CLIENT$$$$$" |
---|
41 | #define REGISTER_PERF_CLIENT_LENGTH 28 // length of REGISTER_PERF_CLIENT string |
---|
42 | #define SEND_STAT_CLIENT_LENGTH 28 // length of SEND_STAT_CLIENT string |
---|
43 | #define CLOSING_STAT_CLIENT "$$CLOSING_STAT_PERF_CLIENT$$" |
---|
44 | #define CLOSING_STAT_CLIENT_LENGTH 28 |
---|
45 | #define CLOSING_PERF_CLIENT "$$CLOSING_PERF_DAEMON_CLASS$" |
---|
46 | #define CLOSING_PERF_CLIENT_LENGTH 28 |
---|
47 | |
---|
48 | class QUANTAnet_tcpClient_c; |
---|
49 | |
---|
50 | /** This class is a very low-level class that is designed for specific uses. |
---|
51 | If what you want to do is checking performance characteristics of your |
---|
52 | application, you don't have to use this class at all. All QUANTA |
---|
53 | classes are updated with instrumentation features. |
---|
54 | |
---|
55 | QUANTAnet_perfDaemonClient_c is a specially designed class |
---|
56 | specifically for use with QUANTAnet_perfDaemon_c class or performance |
---|
57 | monitoring daemon application that instantiates and utilizes QUANTAnet_perfDaemon_c class. |
---|
58 | This class can be used if you want to do one of the following: |
---|
59 | |
---|
60 | First, it can be used to communicate directly with performance daemon. If you want |
---|
61 | to send special messages to the daemon, you can use this class for the purpose. |
---|
62 | Second, you are developing real time performance monitoring applications like QoSiMoto. |
---|
63 | |
---|
64 | If you want to send your own special messages to performance monitoring daemon, |
---|
65 | you have to simply instantiate this class and use provided methods to send special |
---|
66 | messages to the performance daemon. If your interest is in monitoring the performance |
---|
67 | characteristics of other applications then you need to register as performance |
---|
68 | monitoring client when you instantiate this class. Read the description of constructors |
---|
69 | to find out how to register your application as performance monitoring client. |
---|
70 | */ |
---|
71 | class QUANTAnet_perfDaemonClient_c |
---|
72 | { |
---|
73 | private: |
---|
74 | QUANTAnet_tcpClient_c *client; |
---|
75 | int timeOut; |
---|
76 | int connectionAlive; |
---|
77 | int perfClient; |
---|
78 | |
---|
79 | public: |
---|
80 | //@{ |
---|
81 | /// Status ok. |
---|
82 | static const int OK/* = 1*/; |
---|
83 | |
---|
84 | /// Status failed. |
---|
85 | static const int FAILED/* = 2*/; |
---|
86 | |
---|
87 | /// Memory allocation error. |
---|
88 | static const int MEM_ALLOC_ERR/* = 3*/; |
---|
89 | |
---|
90 | /// A non-blocking read had no data available to read. |
---|
91 | static const int NON_BLOCKING_HAS_NO_DATA/* = 7*/; |
---|
92 | |
---|
93 | /// Connection terminated. |
---|
94 | static const int CONNECTION_TERMINATED/* = 8*/; |
---|
95 | |
---|
96 | /// Connection not ready for use. |
---|
97 | static const int NOT_READY/* = 9*/; |
---|
98 | |
---|
99 | /// Connection has data available to read. |
---|
100 | static const int READY_TO_READ/* = 10*/; |
---|
101 | |
---|
102 | /// Connection is ready to write. |
---|
103 | static const int READY_TO_WRITE/* = 11*/; |
---|
104 | |
---|
105 | /// Connection has data available to read and is ready to write. |
---|
106 | static const int READY_TO_READ_AND_WRITE/* = 12*/; |
---|
107 | |
---|
108 | static const int BLOCKING/* = QUANTAnet_tcpClient_c::BLOCKING*/; |
---|
109 | static const int NON_BLOCKING/* = QUANTAnet_tcpClient_c::NON_BLOCKING*/; |
---|
110 | |
---|
111 | static const int NO_TIME_OUT/* = QUANTAnet_tcpClient_c::NO_TIME_OUT*/; |
---|
112 | |
---|
113 | //@} |
---|
114 | |
---|
115 | /** Constructor |
---|
116 | @param isPerfClient 1 if your application is designed to monitor |
---|
117 | the performance characteristics of other applications like QoSiMoto. |
---|
118 | Otherwise, specify 0. |
---|
119 | */ |
---|
120 | QUANTAnet_perfDaemonClient_c(int isPerfClient = 0); |
---|
121 | |
---|
122 | /// Use this constructor if you have a pre-opened socket |
---|
123 | QUANTAnet_perfDaemonClient_c(QUANTAnet_tcpClient_c*, int isPerfClient = 0); |
---|
124 | ~QUANTAnet_perfDaemonClient_c(); |
---|
125 | |
---|
126 | /** Read data from a reflector (if available). |
---|
127 | @param blockingType set to either QUANTAnet_perfDaemonClient_c::BLOCKING, NON_BLOCKING. |
---|
128 | @param ret set to a pointer to a char*. Read will allocate memory for the |
---|
129 | buffer and assign it to your pointer. You are responsible for deleteing |
---|
130 | the buffer once you are done with it. |
---|
131 | @param nbytes returns the number of bytes in the buffer. |
---|
132 | @return Either QUANTAnet_perfDaemonClient_c::MEM_ALLOC_ERR, OK, FAILED, NON_BLOCKING_HAS_NO_DATA, CONNECTION_TERMINATED. |
---|
133 | */ |
---|
134 | int read(char** ret, int* nbytes, int blockingType); |
---|
135 | |
---|
136 | /** Write data to the reflector. |
---|
137 | @param outgoingData set to your buffer containing data. |
---|
138 | @param nbytes set to size of the buffer refered to by outgoingData |
---|
139 | @return Either QUANTAnet_perfDaemonClient_c::OK,CONNECTION_TERMINATED. |
---|
140 | */ |
---|
141 | int write(const char* outgoingData, int* nbytes); |
---|
142 | |
---|
143 | /** Determines if a socket has data available to read. |
---|
144 | @return Either: QUANTAnet_perfDaemonClient_c::NOT_READY |
---|
145 | or QUANTAnet_perfDaemonClient_c::READY_TO_READ |
---|
146 | */ |
---|
147 | int isReadyToRead(); |
---|
148 | |
---|
149 | /** Determines if a socket is ready to write. |
---|
150 | @return Either: QUANTAnet_perfDaemonClient_c::NOT_READY |
---|
151 | or QUANTAnet_perfDaemonClient_c::READY_TO_WRITE |
---|
152 | */ |
---|
153 | int isReadyToWrite(); |
---|
154 | |
---|
155 | /** Determines if a socket is ready to write or read or both. |
---|
156 | @return Either: QUANTAnet_perfDaemonClient_c::NOT_READY |
---|
157 | or QUANTAnet_perfDaemonClient_c::READY_TO_WRITE |
---|
158 | or QUANTAnet_perfDaemonClient_c::READY_TO_READ |
---|
159 | or QUANTAnet_perfDaemonClient_c::READY_TO_READ_AND_WRITE |
---|
160 | */ |
---|
161 | int isReady(); |
---|
162 | |
---|
163 | /// Accessor functions |
---|
164 | //@{ |
---|
165 | /** Get the IP address of remote connection. |
---|
166 | If you are a client this returns the ip of the destination server. |
---|
167 | If you are a server this returns the ip of the destination client. |
---|
168 | */ |
---|
169 | unsigned int getRemoteIP(); |
---|
170 | |
---|
171 | /** Get the IP address of remote connection. |
---|
172 | If you are a client this returns the ip of the destination server. |
---|
173 | If you are a server this returns the ip of the destination client. |
---|
174 | */ |
---|
175 | void getRemoteIP(char* name); |
---|
176 | |
---|
177 | /// Get port of self. |
---|
178 | int getSelfPort(); |
---|
179 | |
---|
180 | /// Get port of client. |
---|
181 | int getRemotePort(); |
---|
182 | //@} |
---|
183 | |
---|
184 | /// Show status of connection in English. |
---|
185 | void showStatus(int status, int nbytes); |
---|
186 | |
---|
187 | /// Show statistics of a connection. |
---|
188 | void showStats(); |
---|
189 | |
---|
190 | /// Close the current client connection. |
---|
191 | void close(); |
---|
192 | |
---|
193 | /** Connect to a server. |
---|
194 | @param ip IP address to connect to. |
---|
195 | @param port Port to connect to. |
---|
196 | @return Either: QUANTAnet_perfDaemonClient_c::OK or FAILED |
---|
197 | */ |
---|
198 | int connectToServer(const char* ip, int port=PERF_DAEMON_DEFAULT_PORT); |
---|
199 | |
---|
200 | /** Set timeout for read and writes. By default no time out is set. |
---|
201 | Setting time out means that if the read or write is unsuccessful |
---|
202 | after a certain amount of time the connection will be terminated. |
---|
203 | This is to prevent you from doing subsequent writes or reads |
---|
204 | from the stream and getting incorrect data. |
---|
205 | In order to re-establish the connection you need to instantiate another |
---|
206 | object of this type. |
---|
207 | */ |
---|
208 | void setTimeOut(int timeout=QUANTAnet_perfDaemonClient_c::NO_TIME_OUT); |
---|
209 | }; |
---|
210 | #endif |
---|
211 | |
---|