source: Sophya/trunk/SophyaPI/PIext/pisiadw.cc@ 3370

Last change on this file since 3370 was 3366, checked in by ansari, 18 years ago

Tentative pour regler le probleme de blocage de piapp suite a affichage de la fefenetre de gestion d'objets.

1/ Protection dans NamedObjMgr() pour eviter deadlock de mutex (ds NamedObjMgr::UpdateObjMgrWindow() en particulier)
2/ Introduction de la classe SOpExObj (fichier piacmd.h .cc) pour execution d'operations sur objets, initiees depuis la boucle d'evts, dans un thread separe.

Reza , 30/10/2007

File size: 8.0 KB
Line 
1#include "sopnamsp.h"
2#include "machdefs.h"
3#include <stdlib.h>
4#include <stdio.h>
5#include <string.h>
6
7#include <typeinfo>
8
9#include "perrors.h"
10#include "ctimer.h"
11
12#include "nbmath.h"
13
14#include "pistdimgapp.h"
15#include "nobjmgr.h"
16#include "servnobjm.h"
17
18
19
20/* ........................................................... */
21/* Classe ObjMgrWind interface de gestion d'objets nommes */
22/* ........................................................... */
23
24/* --Methode-- */
25ObjMgrWind::ObjMgrWind(PIStdImgApp *par)
26: PIWindow((PIMsgHandler *)par, "objmgr", PIWK_normal,
27 400, 300, 250, 250)
28{
29int i;
30dap = par;
31
32int bsx, bsy;
33int tsx, tsy;
34int spx, spy;
35// On definit la taille a partir de la taille par defaut des composantes
36PIApplicationPrefCompSize(bsx, bsy);
37spx = bsx/4; spy = bsy/4;
38tsx = 4.0*bsx+3*spx; tsy = 6*bsy+7*spy;
39SetSize(tsx,tsy);
40dirlist = new PIOptMenu(this, "dirlist", 2.5*bsx, bsy, spx+0.25*bsx, spy);
41dirlist->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
42objlist = new PIList(this, "objlist", 3*bsx, tsy-3*spy-bsy, spx, 2*spy+bsy);
43objlist->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
44// objlist->SetBorderWidth(2);
45
46int py = spy;
47int px = 2*spx+3*bsx;
48mBut[0] = new PIButton(this, "SetCurObj", 10, bsx, bsy, px, py); py += (bsy+spy);
49mBut[1] = new PIButton(this, "Display", 20, bsx, bsy, px, py); py += (bsy+spy);
50mBut[2] = new PIButton(this, "Print", 30, bsx, bsy, px, py); py += (bsy+spy);
51mBut[3] = new PIButton(this, "SavePPF", 40, bsx, bsy, px, py); py += (bsy+spy);
52mBut[4] = new PIButton(this, "Delete", 50, bsx, bsy, px, py); py += (bsy+spy);
53mBut[5] = new PIButton(this, "Dismiss", 90, bsx, bsy, px, py); py += (bsy+spy);
54
55for(i=0; i<6; i++)
56 mBut[i]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
57
58// FinishCreate(); pas necessaire ?
59}
60
61/* --Methode-- */
62ObjMgrWind::~ObjMgrWind()
63{
64int i;
65delete dirlist;
66delete objlist;
67for(i=0; i<6; i++) delete mBut[i];
68}
69
70/* --Methode-- */
71void ObjMgrWind::Show()
72{
73PIWindow::Show();
74dap->ObjMgr()->UpdateObjMgrWindow( -1 );
75return;
76}
77/* --Methode-- */
78void ObjMgrWind::Hide()
79{
80dap->ObjMgr()->SetObjMgrWindowVisibility(false);
81PIWindow::Hide();
82return;
83}
84
85/* --Methode-- */
86void ObjMgrWind::Process(PIMessage msg, PIMsgHandler* sender, void* /*data*/)
87{
88
89if (sender == objlist) return; // Changement de selection d'objet - on ne fait rien
90 // PIMessage ssg = ModMsg(msg);
91msg = UserMsg(msg);
92if (msg == 90) {
93 dap->SetReady();
94 this->Hide();
95 return;
96 }
97else if (msg >= 30000) {
98 dap->ObjMgr()->UpdateObjMgrWindow(msg-30000);
99 return;
100 }
101/*
102 else if (msg == 10) {
103 string cdir = dirlist->GetValueStr();
104 dap->ObjMgr()->SetCurrentDir(cdir);
105 return;
106 }
107*/
108
109string nom = "";
110string sel = "";
111if ( (msg == 10) || (msg == 20) || (msg == 30) || (msg == 40) || (msg == 50) ) {
112 sel = objlist->GetSelectionStr();
113 // size_t p = sel.find_first_not_of(" \t");
114 // if (p<0) p = 0;
115 size_t l = sel.length();
116 size_t q = sel.find_first_of(" \t");
117 if (q > l) q = l;
118 nom = dirlist->GetValueStr() + '/' + sel.substr(0, q);
119 }
120
121NamedObjMgr* om = dap->ObjMgr();
122if (om == NULL) return;
123if (sel.length() < 1) return;
124if (nom.length() < 1) return;
125
126string cmd;
127switch (msg)
128 {
129 case 10:
130 cmd = "SCO " + nom;
131 break;
132 case 20:
133 cmd = "DIS " + nom;
134 break;
135 case 30:
136 cmd = "PRT " + nom;
137 break;
138 case 40:
139 cmd = "SAV " + nom;
140 break;
141 case 50:
142 cmd = "DEL " + nom;
143 break;
144
145 default:
146 // printf("DEBUG/ObjMgrW::Process %d %d \n", (int)msg, (int)ssg);
147 break;
148 }
149 dap->getSOpExObj()->AddOpe(cmd);
150return;
151}
152
153/* --Methode-- */
154void ObjMgrWind::UpdateList(int did)
155{
156if (!Visible()) return;
157if ( (did >0) &&(did != GetCurDirId()) ) return;
158dap->ObjMgr()->UpdateObjMgrWindow(did);
159return;
160}
161
162/* --Methode-- */
163void ObjMgrWind::AddObjList(int did, const char * objn, int oid)
164{
165if (!Visible()) return;
166if (did != (dirlist->GetValue()-30000) ) return;
167mNitem++; objlist->AppendItem(objn, oid);
168}
169
170/* --Methode-- */
171void ObjMgrWind::DelObjList(int did, int oid)
172{
173if (!Visible()) return;
174//DBG printf("DBG-DelObjList %d , %d , (%d) \n", did, dirlist->GetValue()-30000, oid);
175if (did != (dirlist->GetValue()-30000) ) return;
176objlist->DeleteItemMsg(oid);
177}
178
179/* ........................................................... */
180/* Classe PPInMgrWind interface de gestion d'objets nommes */
181/* ........................................................... */
182
183/* --Methode-- */
184PPInMgrWind::PPInMgrWind(PIStdImgApp *par)
185: PIWindow((PIMsgHandler *)par, "PPF-FileManager", PIWK_dialog,
186 400, 300, 250, 250)
187{
188int i;
189dap = par;
190
191int bsx, bsy;
192int tsx, tsy;
193int spx, spy;
194// On definit la taille a partir de la taille par defaut des composantes
195PIApplicationPrefCompSize(bsx, bsy);
196spx = bsx/4; spy = bsy/3;
197bsx *= 1.25;
198ttx = tsx = 3*bsx+8*spx; tty = tsy = 7*bsy+5*spy;
199SetSize(tsx,tsy);
200
201mLab[0] = new PILabel(this, "filename", tsx-spx, bsy-spy, spx/2, spy/2);
202mLab[0]->SetLabel("");
203mLab[0]->SetBinding(PIBK_elastic, PIBK_elastic, PIBK_elastic,PIBK_elastic);
204mLab[0]->SetBorderWidth(1);
205
206polx = spx/2; poly = bsy+1.5*spy;
207tolx = tsx-spx; toly = tsy-2*bsy-5*spy;
208int py = tsy-2*spy-bsy;
209int px = 2*spx;
210mBut[0] = new PIButton(this, "Read", 2500, bsx, bsy, px, py); px += (bsx+2*spx);
211mBut[1] = new PIButton(this, "ReadAll", 2600, bsx, bsy, px, py); px += (bsx+2*spx);
212mBut[2] = new PIButton(this, "Close", 2700, bsx, bsy, px, py); px += (bsx+2*spx);
213
214for(i=0; i<3; i++)
215 mBut[i]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
216
217objlist = NULL;
218mLab[1] = NULL;
219mPin = NULL;
220
221// FinishCreate(); pas necessaire
222}
223
224/* --Methode-- */
225PPInMgrWind::~PPInMgrWind()
226{
227int i;
228if (objlist) delete objlist;
229delete mLab[0];
230for(i=0; i<3; i++) delete mBut[i];
231}
232
233/* --Methode-- */
234void PPInMgrWind::SetFile(string flnm)
235{
236char strg[128];
237char* nom;
238char noms[32];
239int i, cid, key, ln;
240
241bool ok = true;
242#ifdef SANS_EVOLPLANCK
243TRY {
244 mPin = new PInPersist(flnm);
245} CATCH(merr)
246 { printf("ObjMgrWind::SetFile Exception= %ld (%s) \n", (long)merr, PeidaExc(merr));
247 ok = false; } ENDTRY;
248#else
249try {
250 mPin = new PInPersist(flnm);
251 }
252catch (IOExc iox) {
253 cerr << "ObjMgrWind::SetFile/Error Exception - Msg= " << iox.Msg() << endl;
254 ok = false;
255 }
256#endif
257
258if (!ok) { mPin = NULL; dap->SetReady(); return; }
259
260int nbtags = 0;
261#ifdef SANS_EVOLPLANCK
262nbtags = mPin->NbTags();
263#else
264nbtags = mPin->NbNameTags();
265#endif
266
267if (nbtags < 1) {
268 delete mPin; mPin = NULL;
269 string no="";
270 dap->ObjMgr()->ReadObj(flnm,no);
271 return;
272}
273if (objlist) delete objlist;
274SetSize(ttx,tty);
275mLab[0]->SetLabel(flnm);
276objlist = new PIList(this, "infileobjlist", tolx, toly, polx, poly);
277objlist->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
278objlist->SetBorderWidth(2);
279
280
281#ifdef SANS_EVOLPLANCK
282for(i=0; i<mPin->NbTags(); i++) {
283 key = mPin->TagKey(i, cid, ln); // $CHECK$ non-const & reference initialized to temporary, car int -> long&
284 if (ln <= 0) nom = "?";
285 else { strncpy(noms, mPin->TagName(i).c_str(), 31); noms[31] = '\0'; nom = noms; }
286 sprintf(strg, "%s (T=%s, Key=%d)", nom, dap->ObjMgr()->GetServiceObj()->PClassIdToClassName(cid), key);
287 // sprintf(strg, "%s (T=%s, Key=%d)", nom, " DataObject ?", key); Attention SANS_EVOLPLANCK
288 objlist->AppendItem(strg, 5000+i);
289}
290#else
291string tn;
292for(i=0; i<mPin->NbNameTags(); i++) {
293 tn = mPin->GetTagName(i);
294 objlist->AppendItem(tn.c_str(), 5000+i);
295}
296#endif
297
298}
299
300/* --Methode-- */
301void PPInMgrWind::Show()
302{
303if (mPin == NULL) return;
304dap->SetBlocked();
305PIWindow::Show();
306return;
307}
308
309/* --Methode-- */
310void PPInMgrWind::Process(PIMessage msg, PIMsgHandler* /*sender*/, void* /*data*/)
311{
312
313int sel;
314msg = UserMsg(msg);
315
316if (msg == 2700) {
317 delete mPin; mPin = NULL;
318 delete objlist; objlist = NULL;
319 dap->SetReady();
320 this->Hide();
321 return;
322}
323
324NamedObjMgr* om = dap->ObjMgr();
325switch (msg)
326 {
327 case 2500:
328 sel = (PIMessage)objlist->GetSelection() - 5000;
329 if (sel >= 0) om->ReadObj((*mPin), sel);
330 break;
331 case 2600:
332 om->ReadObj((*mPin), -1);
333 dap->SetReady();
334 this->Hide();
335 break;
336
337 default:
338 break;
339 }
340
341return;
342}
Note: See TracBrowser for help on using the repository browser.