1 | /****************************************************************************** |
---|
2 | * SAGE - Scalable Adaptive Graphics Environment |
---|
3 | * |
---|
4 | * Module: messageInterface.h |
---|
5 | * Author : Byungil Jeong |
---|
6 | * |
---|
7 | * Copyright (C) 2004 Electronic Visualization Laboratory, |
---|
8 | * University of Illinois at Chicago |
---|
9 | * |
---|
10 | * All rights reserved. |
---|
11 | * |
---|
12 | * Redistribution and use in source and binary forms, with or without |
---|
13 | * modification, are permitted provided that the following conditions are met: |
---|
14 | * |
---|
15 | * * Redistributions of source code must retain the above copyright |
---|
16 | * notice, this list of conditions and the following disclaimer. |
---|
17 | * * Redistributions in binary form must reproduce the above |
---|
18 | * copyright notice, this list of conditions and the following disclaimer |
---|
19 | * in the documentation and/or other materials provided with the distribution. |
---|
20 | * * Neither the name of the University of Illinois at Chicago nor |
---|
21 | * the names of its contributors may be used to endorse or promote |
---|
22 | * products derived from this software without specific prior written permission. |
---|
23 | * |
---|
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
---|
27 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
---|
28 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
---|
29 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
---|
30 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
---|
31 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
---|
32 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
---|
33 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
---|
34 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
35 | * |
---|
36 | * Direct questions, comments etc about SAGE to sage_users@listserv.uic.edu or |
---|
37 | * http://www.evl.uic.edu/cavern/forum/ |
---|
38 | * |
---|
39 | *****************************************************************************/ |
---|
40 | |
---|
41 | #ifndef _MSGINTF_H |
---|
42 | #define _MSGINTF_H |
---|
43 | |
---|
44 | #include "sage.h" |
---|
45 | #include "QUANTAnet_tcp_c.hxx" |
---|
46 | |
---|
47 | class msgInfConfig { |
---|
48 | public: |
---|
49 | bool master; |
---|
50 | char serverIP[SAGE_IP_LEN]; |
---|
51 | int serverPort; |
---|
52 | |
---|
53 | msgInfConfig() : serverPort(0), master(true) { serverIP[0] = '\0'; } |
---|
54 | }; |
---|
55 | |
---|
56 | class messageInterface { |
---|
57 | private: |
---|
58 | QUANTAnet_tcpServer_c *msgServer; |
---|
59 | std::vector<QUANTAnet_tcpClient_c *> msgClientList; |
---|
60 | msgInfConfig config; |
---|
61 | int readIdx; |
---|
62 | int maxClientSockFd; |
---|
63 | fd_set clientFds; |
---|
64 | static void* connectionThread(void *args); |
---|
65 | bool infEnd; |
---|
66 | pthread_t conThreadID; |
---|
67 | |
---|
68 | public: |
---|
69 | messageInterface(); |
---|
70 | ~messageInterface(); |
---|
71 | int init(msgInfConfig &conf); |
---|
72 | int connect(char *ip, int port); |
---|
73 | int checkClients(); |
---|
74 | int waitForConnection(); |
---|
75 | int readMsg(sageMessage *msg, int timeOut = -1); |
---|
76 | // return (clientID+1) : data read, return 0 : no data, return -1 : error |
---|
77 | // timeOut < 0 : blocking read (default) |
---|
78 | // timeOut = 0 : non-blocking read |
---|
79 | // timeOut > 0 : blocking read with time-out in micro second |
---|
80 | |
---|
81 | int distributeMessage(sageMessage &msg, int *clientList, int clientNum); |
---|
82 | int distributeMessage(int code, int instID, int *clientList, int clientNum); |
---|
83 | int distributeMessage(int code, int instID, int data, int *clientList, int clientNum); |
---|
84 | int distributeMessage(int code, int instID, char *data, int *clientList, int clientNum); |
---|
85 | int msgToClient(sageMessage &msg); |
---|
86 | int msgToClient(int cId, int instID, int code); |
---|
87 | int msgToClient(int cId, int instID, int code, int data); |
---|
88 | int msgToClient(int cId, int instID, int code, char *data); |
---|
89 | int msgToServer(int instID, int code); |
---|
90 | int msgToServer(int instID, int code, int data); |
---|
91 | int msgToServer(int instID, int code, char *data); |
---|
92 | int getNumClients() { return msgClientList.size(); } |
---|
93 | int shutdown(); |
---|
94 | }; |
---|
95 | |
---|
96 | #endif |
---|