]> rtime.felk.cvut.cz Git - orte.git/blob - orte/contrib/shape/FSubscriber.ui.h
New version of shapedemo
[orte.git] / orte / contrib / shape / FSubscriber.ui.h
1 /****************************************************************************
2 ** ui.h extension file, included from the uic-generated form implementation.
3 **
4 ** If you wish to add, delete or rename functions or slots use
5 ** Qt Designer which will update this file, preserving your code. Create an
6 ** init() function in place of a constructor, and a destroy() function in
7 ** place of a destructor.
8 *****************************************************************************/
9 #include <stdio.h>
10 #include <qtimer.h> 
11
12 void FSubscriber::init()
13 {
14     ORTEInit(); 
15     domain=ORTEDomainAppCreate(ORTE_DEFAULT_DOMAIN,NULL,NULL,ORTE_FALSE);
16     ORTETypeRegisterBoxType(domain);
17     subscriberBlue=subscriberGreen=subscriberRed=NULL;
18     subscriberBlack=subscriberYellow=NULL;
19     pthread_mutex_init(&mutex,NULL);
20 }
21
22 void FSubscriber::closeEvent( QCloseEvent *e )
23 {
24     destroy();
25     e->accept();
26 }
27
28 void FSubscriber::destroy()
29 {
30     if (domain) {
31       ORTEDomainAppDestroy(domain);
32       domain=NULL;
33       pthread_mutex_destroy(&mutex);
34     }
35 }
36
37 void
38 recvCallBack(const ORTERecvInfo *info,void *vinstance, void *recvCallBackParam) {
39   BoxType *boxType=(BoxType*)vinstance;
40   FSubscriber *s=(FSubscriber*)recvCallBackParam;
41   QRect   rect;
42
43   switch (info->status) {
44     case NEW_DATA:
45       pthread_mutex_lock(&s->mutex);
46       rect.setCoords(
47           boxType->rectangle.top_left_x,
48           boxType->rectangle.top_left_y,
49           boxType->rectangle.bottom_right_x,
50           boxType->rectangle.bottom_right_y);
51       s->view->activateObject(boxType->color,boxType->color,boxType->shape);
52       s->view->setPosition(boxType->color,rect);
53       pthread_mutex_unlock(&s->mutex);
54       break;
55     case DEADLINE:
56       if (strcmp(info->topic,"Blue")==0)
57         s->view->deactivateObject(0);
58       if (strcmp(info->topic,"Green")==0)
59         s->view->deactivateObject(1);
60       if (strcmp(info->topic,"Red")==0)
61         s->view->deactivateObject(2);
62       if (strcmp(info->topic,"Black")==0)
63         s->view->deactivateObject(3);
64       if (strcmp(info->topic,"Yellow")==0)
65         s->view->deactivateObject(4);
66       break;
67   }
68 }
69
70
71 void FSubscriber::initSubscribers( int iBlue, int iGreen, int iRed, int iBlack, int iYellow )
72 {
73     NtpTime deadline;
74     
75     NtpTimeAssembFromMs(msBlue, 0, 0);
76     NtpTimeAssembFromMs(msGreen, 0, 0);
77     NtpTimeAssembFromMs(msRed, 0, 0);
78     NtpTimeAssembFromMs(msBlack, 0, 0);
79     NtpTimeAssembFromMs(msYellow, 0, 0);
80     NtpTimeAssembFromMs(deadline, 6, 0);
81     if (iBlue) {
82         subscriberBlue=ORTESubscriptionCreate(
83             domain,
84             IMMEDIATE,
85             BEST_EFFORTS,
86             "Blue",
87             "BoxType",
88             &boxTypeBlue,
89             &deadline,
90             &msBlue,
91             recvCallBack,
92             this);
93         combo->insertItem("Blue",combo->count());
94     }
95     if (iGreen) {
96         subscriberGreen=ORTESubscriptionCreate(
97             domain,
98             IMMEDIATE,
99             BEST_EFFORTS,
100             "Green",
101             "BoxType",
102             &boxTypeGreen,
103             &deadline,
104             &msGreen,
105             recvCallBack,
106             this);
107         combo->insertItem("Green",combo->count());
108     }
109     if (iRed) {
110         subscriberRed=ORTESubscriptionCreate(
111             domain,
112             IMMEDIATE,
113             BEST_EFFORTS,
114             "Red",
115             "BoxType",
116             &boxTypeRed,
117             &deadline,
118             &msRed,
119             recvCallBack,
120             this);
121         combo->insertItem("Red",combo->count());
122     }
123     if (iBlack) {
124         subscriberBlack=ORTESubscriptionCreate(
125             domain,
126             IMMEDIATE,
127             BEST_EFFORTS,
128             "Black",
129             "BoxType",
130             &boxTypeBlack,
131             &deadline,
132             &msBlack,
133             recvCallBack,
134             this);
135         combo->insertItem("Black",combo->count());
136     }
137     if (iYellow) {
138         subscriberYellow=ORTESubscriptionCreate(
139             domain,
140             IMMEDIATE,
141             BEST_EFFORTS,
142             "Yellow",
143             "BoxType",
144             &boxTypeYellow,
145             &deadline,
146             &msYellow,
147             recvCallBack,
148             this);
149         combo->insertItem("Yellow",combo->count());
150      }
151 }
152
153
154 void FSubscriber::comboActivated( int )
155 {
156     if  (combo->currentText()==QString("Blue")) 
157         slider->setValue(msBlue.seconds);
158     if  (combo->currentText()==QString("Green")) 
159         slider->setValue(msGreen.seconds);
160     if  (combo->currentText()==QString("Red")) 
161         slider->setValue(msRed.seconds);
162     if  (combo->currentText()==QString("Black")) 
163         slider->setValue(msBlack.seconds);
164     if  (combo->currentText()==QString("Yellow")) 
165         slider->setValue(msYellow.seconds);
166 }
167
168
169 void FSubscriber::sliderValueChanged( int  value)
170 {
171     NtpTime minSep;
172     ORTESubsProp  sp;
173   
174     NtpTimeAssembFromMs(minSep, value, 0);
175     if  (combo->currentText()==QString("Blue")) {
176          msBlue=minSep;
177          ORTESubscriptionPropertiesGet(subscriberBlue,&sp);
178          sp.minimumSeparation=msBlue;
179          ORTESubscriptionPropertiesSet(subscriberBlue,&sp);    
180     }
181     if  (combo->currentText()==QString("Green")) {
182          msGreen=minSep;
183          ORTESubscriptionPropertiesGet(subscriberGreen,&sp);
184          sp.minimumSeparation=msGreen;
185          ORTESubscriptionPropertiesSet(subscriberGreen,&sp);    
186     }
187     if  (combo->currentText()==QString("Red")) {
188          msRed=minSep;
189          ORTESubscriptionPropertiesGet(subscriberRed,&sp);
190          sp.minimumSeparation=msRed;
191          ORTESubscriptionPropertiesSet(subscriberRed,&sp);    
192     }
193     if  (combo->currentText()==QString("Black")) { 
194          msBlack=minSep;
195          ORTESubscriptionPropertiesGet(subscriberBlack,&sp);
196          sp.minimumSeparation=msBlack;
197          ORTESubscriptionPropertiesSet(subscriberBlack,&sp);    
198     }
199     if  (combo->currentText()==QString("Yellow")) {
200          msYellow=minSep;
201          ORTESubscriptionPropertiesGet(subscriberYellow,&sp);
202          sp.minimumSeparation=msYellow;
203          ORTESubscriptionPropertiesSet(subscriberYellow,&sp);    
204     }
205 }