]> rtime.felk.cvut.cz Git - orte.git/blob - orte/contrib/shape/Subscriber.cpp
OCERA SF CVS tree of ORTE framework updated to
[orte.git] / orte / contrib / shape / Subscriber.cpp
1 #include "Subscriber.h"
2 #include <qtimer.h>
3 #include <qrect.h>
4 #include <orte_api.h>
5
6
7 Subscriber::Subscriber( QWidget *parent, const char *name )
8         : QWidget( parent, name )
9 {
10 }
11
12 void
13 recvCallBack(const ORTERecvInfo *info,void *vinstance, void *recvCallBackParam) {
14   BoxType *boxType=(BoxType*)vinstance;
15   Subscriber *s=(Subscriber*)recvCallBackParam;
16   QRect   rect;
17
18   switch (info->status) {
19     case NEW_DATA:
20       rect.setCoords(
21           boxType->rectangle.top_left_x,
22           boxType->rectangle.top_left_y,
23           boxType->rectangle.bottom_right_x,
24           boxType->rectangle.bottom_right_y);
25       pthread_mutex_lock(&s->mutex);
26       s->m_mainFrm->ShapeColorRect(boxType->color,boxType->shape,boxType->color,rect);
27       pthread_mutex_unlock(&s->mutex);
28       break;
29     case DEADLINE:
30 //      printf("deadline occured\n");
31       break;
32   }
33 }
34
35 void Subscriber::Create(QString name, char eBlue,char eGreen,
36                         char eRed,char eBlack,char eYellow )
37 {
38         subBlue=NULL;
39         NtpTimeAssembFromMs(minimumSeparationBlue, 0, 0);
40         subGreen=NULL;
41         NtpTimeAssembFromMs(minimumSeparationGreen, 0, 0);
42         subRed=NULL;
43         NtpTimeAssembFromMs(minimumSeparationRed, 0, 0);
44         subBlack=NULL;
45         NtpTimeAssembFromMs(minimumSeparationBlack, 0, 0);
46         subYellow=NULL;
47         NtpTimeAssembFromMs(minimumSeparationYellow, 0, 0);
48         
49         //init main frame
50         m_mainFrm = new MainForm;
51         Text = new QLabel( m_mainFrm, "Text" );
52         Text->setGeometry( QRect(10 , 0, 110, 15 ) );
53         Text->setText( trUtf8( "Minimum Separation : " ) );
54         MinSep = new QSlider(m_mainFrm, "str" );
55         MinSep->setGeometry( QRect( 120, 0, 130, 15 ) );
56         MinSep->setMaxValue( 10 );
57         MinSep->setOrientation( QSlider::Horizontal );
58         MinSep->setTickmarks( QSlider::NoMarks );
59         connect( MinSep, SIGNAL( valueChanged(int) ), this, SLOT(changeMinSep() ) );
60         m_mainFrm->show();
61
62
63         //init caption
64         QString topic;
65
66         strTitle="Subscriber : "+name;
67         m_mainFrm->setCaption(strTitle);
68
69         pthread_mutex_init(&mutex,NULL);
70         
71         ORTEInit(); 
72         domain=ORTEDomainAppCreate(ORTE_DEFAULT_DOMAIN,NULL,NULL,ORTE_FALSE);
73         ORTETypeRegisterBoxType(domain);
74         NtpTime deadline;
75         NtpTimeAssembFromMs(deadline, 1, 0);
76         if (eBlue) {
77           subBlue=ORTESubscriptionCreate(
78               domain,
79               IMMEDIATE,
80               BEST_EFFORTS,
81               "Blue",
82               "BoxType",
83               &boxType,
84               &deadline,
85               &minimumSeparationBlue,
86               recvCallBack,
87               this);
88            m_mainFrm->SetActiveObject(0);
89          }
90         if (eGreen) {
91           subGreen=ORTESubscriptionCreate(
92               domain,
93               IMMEDIATE,
94               BEST_EFFORTS,
95               "Green",
96               "BoxType",
97               &boxType,
98               &deadline,
99               &minimumSeparationGreen,
100               recvCallBack,
101               this);
102            m_mainFrm->SetActiveObject(1);
103          }
104         if (eRed) {
105           subRed=ORTESubscriptionCreate(
106               domain,
107               IMMEDIATE,
108               BEST_EFFORTS,
109               "Red",
110               "BoxType",
111               &boxType,
112               &deadline,
113               &minimumSeparationRed,
114               recvCallBack,
115               this);
116            m_mainFrm->SetActiveObject(2);
117          }
118         if (eBlack) {
119           subBlack=ORTESubscriptionCreate(
120               domain,
121               IMMEDIATE,
122               BEST_EFFORTS,
123               "Black",
124               "BoxType",
125               &boxType,
126               &deadline,
127               &minimumSeparationBlack,
128               recvCallBack,
129               this);
130            m_mainFrm->SetActiveObject(3);
131          }
132         if (eYellow) {
133           subYellow=ORTESubscriptionCreate(
134               domain,
135               IMMEDIATE,
136               BEST_EFFORTS,
137               "Yellow",
138               "BoxType",
139               &boxType,
140               &deadline,
141               &minimumSeparationYellow,
142               recvCallBack,
143               this);
144            m_mainFrm->SetActiveObject(4);
145          }
146
147 }
148
149
150 void Subscriber::Destroy()
151 {
152         m_mainFrm->WantClose();
153         m_mainFrm->close();
154         ORTEDomainAppDestroy(domain);
155         pthread_mutex_destroy(&mutex);
156
157 }
158
159
160 void Subscriber::changeMinSep()
161 {
162         ORTESubsProp  sp;
163
164 //        ORTESubscriptionPropertiesGet(subscriber,&sp);
165 //      NtpTimeAssembFromMs(sp.minimumSeparation,MinSep->value(),0);
166 //        ORTESubscriptionPropertiesSet(subscriber,&sp);
167         QString name=QString::number(MinSep->value());
168         if((MinSep->value())<10) name+=" ";
169         (this->strTitle).replace((this->strTitle).length()-3,2,name);
170         (this->m_mainFrm)->setCaption(this->strTitle);
171 }