source: trunk/src/testing/include/sageEvent.h @ 4

Revision 4, 4.3 KB checked in by ajaworski, 13 years ago (diff)

Added modified SAGE sources

Line 
1/***************************************************************************************
2 * SAGE - Scalable Adaptive Graphics Environment
3 *
4 * Module:  sageEvent.h
5 * Author : Byungil Jeong
6 *
7 *   Description: Queue for event driven control in a SAGE component
8 *
9 * Copyright (C) 2004 Electronic Visualization Laboratory,
10 * University of Illinois at Chicago
11 *
12 * 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 *
17 *  * Redistributions of source code must retain the above copyright
18 *    notice, this list of conditions and the following disclaimer.
19 *  * Redistributions in binary form must reproduce the above
20 *    copyright notice, this list of conditions and the following disclaimer
21 *    in the documentation and/or other materials provided with the distribution.
22 *  * Neither the name of the University of Illinois at Chicago nor
23 *    the names of its contributors may be used to endorse or promote
24 *    products derived from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
30 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 *
38 * Direct questions, comments etc about SAGE to sage_users@listserv.uic.edu or
39 * http://www.evl.uic.edu/cavern/forum/
40 *
41*****************************************************************************************/
42
43#ifndef _SAGE_EVENT_H
44#define _SAGE_EVENT_H
45
46#include "sageBase.h"
47#include <queue>
48
49#define SAGE_EVENT_SIZE 1280
50
51#define EVENT_NEW_MESSAGE    100
52#define EVENT_NEW_CONNECTION 101
53#define EVENT_READ_BLOCK     102
54#define EVENT_REFRESH_SCREEN 103
55#define EVENT_SYNC_MESSAGE   104
56#define EVENT_APP_CONNECTED  105
57#define EVENT_AUDIO_CONNECTION 106
58
59#define EVENT_SLAVE_PERF_INFO  200
60#define EVENT_MASTER_PERF_INFO 201
61#define EVENT_APP_SHUTDOWN     202
62#define EVENT_BRIDGE_SHUTDOWN  203
63
64/**
65 * sageEvent
66 */
67class sageEvent {
68public:
69   int eventType;
70   char eventMsg[SAGE_EVENT_SIZE];
71   void *param;
72
73
74        /**
75         * size of the event message.
76         * this is updated when eventMsg is allocated or copied by user
77         */
78        int buflen;
79
80   sageEvent() : eventType(0), param(NULL), buflen(0) {}
81   sageEvent(int type, char* msg, void *p = NULL);
82
83   void setMsg(char *msg) { if (msg) strcpy(eventMsg, msg); }
84};
85
86/**
87 * sageSyncEvent
88 * by sungwon
89 * With no MAX_INST_NUM fix from Hyejung, sync algorithm can't use array
90 * However, there must be upper bound for the number of application instances that can exist simultaneously.
91 * Otherwise, there's no way to determine the size of the sync msg (in the 1st phase of syncMaster).
92 * So, this is temporary fix to increase the msg size a little bit more.
93 * Or this class can be used more cleverly.
94 */
95class sageSyncEvent : public sageEvent {
96        public:
97        //char eventMsg[SAGE_SYNC_MSG_LEN]; /**< overrides sageEvent::eventMsg[] */
98        char *eventMsg;
99
100        /**
101         * sets buflen
102         * returns the size of message
103         * -1 on error
104         */
105        int setMsg(char *msg);
106
107        sageSyncEvent() : eventMsg(NULL) {}
108        sageSyncEvent(int type, int bl, void *p=NULL);
109};
110
111/**
112 * sageEventQueue
113 */
114class sageEventQueue {
115protected:
116   std::deque<sageEvent*> eventQueue;
117
118   pthread_mutex_t *queueLock;
119   pthread_cond_t *notEmpty;
120
121   bool empty;
122
123public:
124   sageEventQueue();
125
126   sageEvent* getEvent();  // get event from the queue
127   void appendEvent(sageEvent* event);
128   void appendEvent(int type, char *msg = NULL, void *param = NULL);
129   void appendEvent(int type, int info, void *param = NULL);
130   void prependEvent(sageEvent* event);
131
132   bool isEmpty()  { return (eventQueue.size() == 0); }
133   ~sageEventQueue();
134};
135
136#endif
Note: See TracBrowser for help on using the repository browser.