]> rtime.felk.cvut.cz Git - vajnamar/orte.git/blob - orte/contrib/shape/FSubscriber.cpp
dabdb9790236d8504da94bc22af35da31a5c8327
[vajnamar/orte.git] / orte / contrib / shape / FSubscriber.cpp
1 #include "FSubscriber.h"
2
3
4 FSubscriber::FSubscriber(QWidget *parent)
5     : QDialog(parent)
6 {
7     subscriberBlue=subscriberGreen=subscriberRed=NULL;
8     subscriberBlack=subscriberYellow=NULL;
9     /* setup UI */
10     setupUi(this);
11 }
12
13 void FSubscriber::closeEvent( QCloseEvent *e )
14 {
15     if (domain)
16       destroy();
17     e->accept();
18 }
19
20 void FSubscriber::destroy()
21 {
22     if (domain) {
23       ORTEDomainAppDestroy(domain);
24       domain=NULL;
25       close();
26     }
27 }
28
29 void
30 recvCallBack(const ORTERecvInfo *info,void *vinstance, void *recvCallBackParam) {
31   BoxType *boxType=(BoxType*)vinstance;
32   FSubscriber *s=(FSubscriber*)recvCallBackParam;
33   QRect   rect;
34
35   switch (info->status) {
36     case NEW_DATA:
37       rect.setCoords(
38           boxType->rectangle.top_left_x,
39           boxType->rectangle.top_left_y,
40           boxType->rectangle.bottom_right_x,
41           boxType->rectangle.bottom_right_y);
42       s->view->activateObject(boxType->color,boxType->color,boxType->shape);
43       s->view->setPosition(boxType->color,rect);
44       break;
45     case DEADLINE:
46       if (strcmp(info->topic,"Blue")==0)
47         s->view->deactivateObject(CL_BLUE);
48       if (strcmp(info->topic,"Green")==0)
49         s->view->deactivateObject(CL_GREEN);
50       if (strcmp(info->topic,"Red")==0)
51         s->view->deactivateObject(CL_RED);
52       if (strcmp(info->topic,"Black")==0)
53         s->view->deactivateObject(CL_BLACK);
54       if (strcmp(info->topic,"Yellow")==0)
55         s->view->deactivateObject(CL_YELLOW);
56       break;
57   }
58 }
59
60
61 bool FSubscriber::initSubscribers( int iBlue, int iGreen, int iRed, int iBlack, int iYellow )
62 {
63     NtpTime deadline;
64     
65     ORTEInit(); 
66     domain=ORTEDomainAppCreate(ORTE_DEFAULT_DOMAIN,NULL,NULL,ORTE_FALSE);
67     if (!domain)
68         return false;
69     BoxType_type_register(domain);
70
71     NtpTimeAssembFromMs(msBlue, 0, 0);
72     NtpTimeAssembFromMs(msGreen, 0, 0);
73     NtpTimeAssembFromMs(msRed, 0, 0);
74     NtpTimeAssembFromMs(msBlack, 0, 0);
75     NtpTimeAssembFromMs(msYellow, 0, 0);
76     NtpTimeAssembFromMs(deadline, 6, 0);
77     if (iBlue) {
78         subscriberBlue=ORTESubscriptionCreate(
79             domain,
80             IMMEDIATE,
81             BEST_EFFORTS,
82             "Blue",
83             "BoxType",
84             &boxTypeBlue,
85             &deadline,
86             &msBlue,
87             recvCallBack,
88             this,
89             IPADDRESS_INVALID);
90         combo->addItem("Blue");
91     }
92     if (iGreen) {
93         subscriberGreen=ORTESubscriptionCreate(
94             domain,
95             IMMEDIATE,
96             BEST_EFFORTS,
97             "Green",
98             "BoxType",
99             &boxTypeGreen,
100             &deadline,
101             &msGreen,
102             recvCallBack,
103             this,
104             IPADDRESS_INVALID);
105         combo->addItem("Green");
106     }
107     if (iRed) {
108         subscriberRed=ORTESubscriptionCreate(
109             domain,
110             IMMEDIATE,
111             BEST_EFFORTS,
112             "Red",
113             "BoxType",
114             &boxTypeRed,
115             &deadline,
116             &msRed,
117             recvCallBack,
118             this,
119             IPADDRESS_INVALID);
120         combo->addItem("Red");
121     }
122     if (iBlack) {
123         subscriberBlack=ORTESubscriptionCreate(
124             domain,
125             IMMEDIATE,
126             BEST_EFFORTS,
127             "Black",
128             "BoxType",
129             &boxTypeBlack,
130             &deadline,
131             &msBlack,
132             recvCallBack,
133             this,
134             IPADDRESS_INVALID);
135         combo->addItem("Black");
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             IPADDRESS_INVALID);
150         combo->addItem("Yellow");
151      }
152      return true;
153 }
154
155
156 void FSubscriber::comboActivated( int )
157 {
158     if  (combo->currentText()==QString("Blue")) 
159         slider->setValue(msBlue.seconds);
160     if  (combo->currentText()==QString("Green")) 
161         slider->setValue(msGreen.seconds);
162     if  (combo->currentText()==QString("Red")) 
163         slider->setValue(msRed.seconds);
164     if  (combo->currentText()==QString("Black")) 
165         slider->setValue(msBlack.seconds);
166     if  (combo->currentText()==QString("Yellow")) 
167         slider->setValue(msYellow.seconds);
168 }
169
170
171 void FSubscriber::sliderValueChanged( int  value)
172 {
173     NtpTime minSep;
174     ORTESubsProp  sp;
175   
176     NtpTimeAssembFromMs(minSep, value, 0);
177     if  (combo->currentText()==QString("Blue")) {
178          msBlue=minSep;
179          ORTESubscriptionPropertiesGet(subscriberBlue,&sp);
180          sp.minimumSeparation=msBlue;
181          ORTESubscriptionPropertiesSet(subscriberBlue,&sp);    
182     }
183     if  (combo->currentText()==QString("Green")) {
184          msGreen=minSep;
185          ORTESubscriptionPropertiesGet(subscriberGreen,&sp);
186          sp.minimumSeparation=msGreen;
187          ORTESubscriptionPropertiesSet(subscriberGreen,&sp);    
188     }
189     if  (combo->currentText()==QString("Red")) {
190          msRed=minSep;
191          ORTESubscriptionPropertiesGet(subscriberRed,&sp);
192          sp.minimumSeparation=msRed;
193          ORTESubscriptionPropertiesSet(subscriberRed,&sp);    
194     }
195     if  (combo->currentText()==QString("Black")) { 
196          msBlack=minSep;
197          ORTESubscriptionPropertiesGet(subscriberBlack,&sp);
198          sp.minimumSeparation=msBlack;
199          ORTESubscriptionPropertiesSet(subscriberBlack,&sp);    
200     }
201     if  (combo->currentText()==QString("Yellow")) {
202          msYellow=minSep;
203          ORTESubscriptionPropertiesGet(subscriberYellow,&sp);
204          sp.minimumSeparation=msYellow;
205          ORTESubscriptionPropertiesSet(subscriberYellow,&sp);    
206     }
207 }
208