Changeset 2491 in Sophya for trunk/SophyaPI/PIext/nobjmgr.cc


Ignore:
Timestamp:
Jan 4, 2004, 8:02:44 PM (22 years ago)
Author:
ansari
Message:

Suite des modifs pour piapp multi-threads
1) Ajout Mutex de synchronisation ds ls classe NamedObjMgr
2) Suite controle de gestion d'appel aux methodes de PIStdImgApp depuis
la classe elle-meme, a travers le NamedObjMgr
3) Modification de la boucle d'evenements, avec un thread de reveil
periodique

Reza, 4 Janvier 2004

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaPI/PIext/nobjmgr.cc

    r2490 r2491  
    3636#include "pigfd1.h"
    3737#include "pigfd2.h"
     38
     39#include "zthread.h"
    3840
    3941
     
    9496static string* TmpDir;  // Repertoire pour les compilations / link dynamique
    9597
     98// Pour gestion multithread
     99static ZMutex* myMutex;
    96100// ..................................................................
    97101
     
    119123  currDir = new string("home");
    120124  string dirn = "home";
    121   CreateDir(dirn);
     125  CreateDir_P(dirn);
    122126  SetKeepOldDirAtt(dirn, false);
    123127  dirn = "tmp";
    124   CreateDir(dirn);
     128  CreateDir_P(dirn);
    125129  SetKeepOldDirAtt(dirn, false);
    126130  dirn = "autoc";
    127   CreateDir(dirn);
     131  CreateDir_P(dirn);
    128132  SetKeepOldDirAtt(dirn, false);
    129133  dirn = "old";
    130   CreateDir(dirn);
     134  CreateDir_P(dirn);
    131135  SetKeepOldDirAtt(dirn, false);
    132136  dirn = "home";
     
    138142  int l = (*TmpDir).length();
    139143  if ( (l>0) && ((*TmpDir)[l-1] != '/') )  (*TmpDir) += '/';
    140   servnobjm = new Services2NObjMgr(this, (*TmpDir));
     144  servnobjm = new Services2NObjMgr(*TmpDir);
     145  myMutex = new ZMutex;
    141146  }
    142147fgOInit++;
     
    154159  delete myDirs;
    155160  delete myVars;
     161  delete myMutex;
    156162}
    157163}
     
    223229    return(false);
    224230  }
     231  ZSync(*myMutex);
    225232#ifdef SANS_EVOLPLANCK
    226233  bool fg = true;
     
    240247    return(false);
    241248  }
     249  ZSync(*myMutex);
    242250#ifdef SANS_EVOLPLANCK
    243251  DVList::ValList::const_iterator it;
     
    257265    return(false);
    258266  }
     267  ZSync(*myMutex);
    259268#ifdef SANS_EVOLPLANCK
    260269  return(false);
     
    271280    return("");
    272281  }
     282  ZSync(*myMutex);
    273283  //  cout << " DEBUG::GetVar " << *myVars << endl;
    274284  return(myVars->GetS(key));
     
    279289{
    280290  //  cout << " DEBUG::GetVarList " << *myVars << endl;
     291  ZSync(*myMutex);
    281292  return(*myVars);
    282293}
     
    284295/* --Methode-- */
    285296bool NamedObjMgr::CreateDir(string & dirname)
     297{
     298  ZSync(*myMutex);
     299  return CreateDir_P(dirname);
     300}
     301
     302/* --Methode-- */
     303bool NamedObjMgr::CreateDir_P(string & dirname)
    286304{
    287305if ( !CheckDirName(dirname) ) {
     
    317335  return(false);
    318336  }
     337ZSync(*myMutex);
    319338NObjDirList::iterator it = myDirs->find(dirname);
    320339if (it == myDirs->end()) {
     
    347366void NamedObjMgr::LockDir(string & dirname)
    348367{
     368ZSync(*myMutex);
    349369if ( !CheckDirName(dirname) ) return;
    350370NObjDirList::iterator it = myDirs->find(dirname);
     
    358378void NamedObjMgr::UnlockDir(string & dirname)
    359379{
     380ZSync(*myMutex);
    360381if ( !CheckDirName(dirname) ) return;
    361382NObjDirList::iterator it = myDirs->find(dirname);
     
    369390void NamedObjMgr::SetKeepOldDirAtt(string & dirname, bool keepold)
    370391{
     392ZSync(*myMutex);
    371393if ( !CheckDirName(dirname) ) return;
    372394NObjDirList::iterator it = myDirs->find(dirname);
     
    384406bool NamedObjMgr::SetCurrentDir(string & dirname)
    385407{
     408ZSync(*myMutex);
    386409if ( !CheckDirName(dirname) ) {
    387410  cout << "NamedObjMgr::SetCurrentDir( " << dirname << ") Error - Invalid name !" << endl;
     
    401424void NamedObjMgr::GetCurrentDir(string & dirname)
    402425{
     426ZSync(*myMutex);
    403427dirname = *currDir;
    404428}
     
    407431void NamedObjMgr::ListDirs(string & patt)
    408432{
     433ZSync(*myMutex);
    409434NObjDirList::iterator it;
    410435string cn;
     
    426451void NamedObjMgr::GetDirList(string & patt, vector<string>& lstd)
    427452{
     453ZSync(*myMutex);
    428454NObjDirList::iterator it;
    429455string cn;
     
    437463/* --Methode-- */
    438464void NamedObjMgr::CleanDir(string & dirname)
     465{
     466ZSync(*myMutex);
     467CleanDir_P(dirname);
     468}
     469
     470/* --Methode-- */
     471void NamedObjMgr::CleanDir_P(string & dirname)
    439472{
    440473if ( !CheckDirName(dirname) ) {
     
    493526//--
    494527
    495 
    496528/* --Methode-- */
    497529bool NamedObjMgr::AddObj(AnyDataObj* obj, string & nom, bool crd)
     530{
     531  ZSync(*myMutex);
     532  return AddObj_P(obj, nom, crd);
     533}
     534
     535/* --Methode-- */
     536bool NamedObjMgr::AddObj_P(AnyDataObj* obj, string & nom, bool crd)
    498537{
    499538
     
    516555    return(false);
    517556    }
    518   else { CreateDir(nrep);  did =  myDirId; }
     557  else { CreateDir_P(nrep);  did =  myDirId; }
    519558  }
    520559
    521560// Si c'est le repertoire /autoc, on nettoie
    522561if (nrep == "autoc")  {
    523   CleanDir(nrep);
     562  CleanDir_P(nrep);
    524563  }
    525564
     
    543582    sprintf(buff, "%d", (*it).second.oid);
    544583    string nomnew = "/autoc/" + nobj + buff;
    545     RenameObj(nom, nomnew);
     584    RenameObj_P(nom, nomnew);
    546585    }                             
    547586  else if ( (*itr).second.keepold ) { // On met l'ancien objet dans /old
     
    550589    sprintf(buff, "%d", (*it).second.oid);
    551590    string nomnew = "/old/" + nobj + buff;
    552     RenameObj(nom, nomnew);
     591    RenameObj_P(nom, nomnew);
    553592    }
    554593  else {  // Sinon, on remplace l'objet
    555594    cout << "NamedObjMgr::AddObj() - Replacing " << nom << endl;
    556     DelObj(nom);
     595    DelObj_P(nom);
    557596    }
    558597  }
     
    581620bool NamedObjMgr::AddObj(AnyDataObj& obj, string & nom, bool crd)
    582621{
     622ZSync(*myMutex);
    583623NObjMgrAdapter* adap = GetServiceObj()->GetAdapter(&obj);
    584624if (adap == NULL) {
     
    592632  return(false);
    593633}
    594 return ( AddObj(cloneobj , nom, crd) );
     634return ( AddObj_P(cloneobj , nom, crd) );
    595635}
    596636
    597637/* --Methode-- */
    598638bool NamedObjMgr::RenameObj(string & nom, string& nomnew)
     639{
     640  ZSync(*myMutex);
     641  return RenameObj_P(nom, nomnew);
     642}
     643
     644/* --Methode-- */
     645bool NamedObjMgr::RenameObj_P(string & nom, string& nomnew)
    599646{
    600647string n1,r1,n2,r2;
     
    657704bool NamedObjMgr::CopyObj(string & nom, string& nomcp)
    658705{
     706ZSync(*myMutex);
    659707if(nomcp.length()<=0)
    660708  {cout<<"NamedObjMgr::CopyObj() Error, copied obj name "<<nomcp<<" not valid"<<endl;
     
    666714AnyDataObj* obnomcp = obnom->CloneDataObj();
    667715if(obnomcp==NULL) return(false);
    668 if(! AddObj(obnomcp,nomcp) ) {delete obnomcp; return(false);}
     716if(! AddObj_P(obnomcp,nomcp,false) ) {delete obnomcp; return(false);}
    669717return true;
    670718}
    671719
    672 
    673720/* --Methode-- */
    674721bool NamedObjMgr::DelObj(string & nom, bool fgd)
     722{
     723  ZSync(*myMutex);
     724  return DelObj_P(nom, fgd);
     725}
     726
     727/* --Methode-- */
     728bool NamedObjMgr::DelObj_P(string & nom, bool fgd)
    675729{
    676730string n1,r1;
     
    713767bool NamedObjMgr::DelObj_Id(int oid)
    714768{
     769ZSync(*myMutex);
    715770NObjList::iterator it;
    716771string nom;
     
    728783void NamedObjMgr::DelObjects(string & patt, bool fgd)
    729784{
     785ZSync(*myMutex);
    730786string n1,r1;
    731787ParseObjectName(patt, r1, n1);
     
    739795  }
    740796list<string>::iterator ii;
    741 for(ii=odel.begin(); ii != odel.end(); ii++)  DelObj(*ii, fgd);
     797for(ii=odel.begin(); ii != odel.end(); ii++)  DelObj_P(*ii, fgd);
    742798}
    743799
     
    745801AnyDataObj* NamedObjMgr::GetObj(string & nom)
    746802{
     803ZSync(*myMutex);
    747804string n1,r1;
    748805ParseObjectName(nom, r1, n1);
     
    756813NObjMgrAdapter* NamedObjMgr::GetObjAdapter(string & nom)
    757814{
     815ZSync(*myMutex);
    758816string n1,r1;
    759817ParseObjectName(nom, r1, n1);
     
    767825void NamedObjMgr::ListObjs(string & patt)
    768826{
     827ZSync(*myMutex);
    769828int k;
    770829AnyDataObj* obj=NULL;
     
    795854void NamedObjMgr::GetObjList(string & patt, vector<string> &lst)
    796855{
     856ZSync(*myMutex);
    797857string n1,r1;
    798858if (patt.length() < 1)  return;
     
    830890void NamedObjMgr::ReadObj(string const & flnm, string & nobj)
    831891{
     892ZSync(*myMutex);
    832893PPersist* ppobj=NULL;
    833894bool ok = true;
     
    852913if (!ok)  return;
    853914if (nobj.length()<1)  nobj = servnobjm->FileName2Name(flnm);
    854 AddObj(ppobj->DataObj(), nobj, true);
     915AddObj_P(ppobj->DataObj(), nobj, true);
    855916cout << "NamedObjMgr::ReadObj(...) object " << nobj << " read from file " << endl;
    856917return;
     
    860921void NamedObjMgr::ReadObj(PInPersist& s, int num)
    861922{
     923ZSync(*myMutex);
    862924int_4 i; // $CHECK$ int -> int_4 a cause de TagKey
    863925#ifdef SANS_EVOLPLANCK
     
    903965  if (!ok)  return;
    904966  nom = "";
    905   AddObj(obj->DataObj(), nom);
     967  AddObj_P(obj->DataObj(), nom, false);
    906968  nread++;
    907969}
     
    933995    }
    934996#endif
    935   if (ok)  { AddObj(obj->DataObj(), nom, true);  nread++; }
     997  if (ok)  { AddObj_P(obj->DataObj(), nom, true);  nread++; }
    936998}
    937999
     
    9421004void NamedObjMgr::ReadAll(string const & flnm)
    9431005{
     1006ZSync(*myMutex);
    9441007bool ok = true;
    9451008PPersist* obj=NULL;
     
    9681031if (obj) {
    9691032  string nom = servnobjm->FileName2Name(flnm);
    970   AddObj(obj->DataObj(), nom);
     1033  AddObj_P(obj->DataObj(), nom, false);
    9711034  }
    9721035else ReadObj((*ppin), -1);
     
    9781041void NamedObjMgr::ReadFits(string const & flnm, string & nobj)
    9791042{
    980 
     1043ZSync(*myMutex);
    9811044#ifdef SANS_EVOLPLANCK
    9821045bool ok = false;
     
    9931056if (ok && (obj != NULL)) {
    9941057  if (nobj.length()<1)  nobj = servnobjm->FileName2Name(flnm);
    995   AddObj((AnyDataObj*)obj, nobj);
     1058  AddObj_P((AnyDataObj*)obj, nobj);
    9961059}
    9971060#else
     
    10181081       }
    10191082       else name = nobj;
    1020        AddObj(obj, name);
     1083       AddObj_P(obj, name, false);
    10211084       kon++;
    10221085     }
     
    10351098}
    10361099
     1100/* --Methode-- */
     1101void NamedObjMgr::SaveObj(string & nom, POutPersist& s, bool keeppath)
     1102{
     1103  ZSync(*myMutex);
     1104  SaveObj_P(nom, s, keeppath);
     1105}
    10371106
    10381107static int key_for_write = 5000;
    10391108/* --Methode-- */
    1040 void NamedObjMgr::SaveObj(string & nom, POutPersist& s, bool keeppath)
     1109void NamedObjMgr::SaveObj_P(string & nom, POutPersist& s, bool keeppath)
    10411110{
    10421111if (nom.length() < 1) return;
     
    10571126void NamedObjMgr::SaveObjects(string & patt, string const& flnm)
    10581127{
     1128ZSync(*myMutex);
    10591129string n1,r1;
    10601130if (patt.length() < 1)  return;
     
    10861156  cn = (*it).first;
    10871157  if (csh_parse(cn.c_str(), patt.c_str()) == 0)  continue;
    1088   SaveObj(cn, (*pout), keeppath);
     1158  SaveObj_P(cn, (*pout), keeppath);
    10891159  }
    10901160delete pout;
     
    10951165void NamedObjMgr::SaveAll(string const& flnm)
    10961166{
     1167ZSync(*myMutex);
    10971168bool ok = true;
    10981169
     
    11181189for(it = myObjs->begin(); it != myObjs->end(); it++) {
    11191190  no = (*it).first;
    1120   SaveObj(no, (*pout), true);
     1191  SaveObj_P(no, (*pout), true);
    11211192  }
    11221193delete pout;
     
    11271198void NamedObjMgr::SaveFits(string& nom, string const & flnm)
    11281199{
     1200ZSync(*myMutex);
     1201
    11291202NObjMgrAdapter* obja=NULL;
    11301203obja = GetObjAdapter(nom);
     
    11391212void NamedObjMgr::PrintObj(string& nom)
    11401213{
     1214ZSync(*myMutex);
    11411215NObjMgrAdapter* obja=NULL;
    11421216obja = GetObjAdapter(nom);
     
    11571231void NamedObjMgr::DisplayObj(string& nom, string dopt)
    11581232{
     1233ZSync(*myMutex);
     1234
    11591235NObjMgrAdapter* obja=NULL;
    11601236obja = GetObjAdapter(nom);
     
    11851261ParseObjectName(nom, r1, n1);
    11861262
     1263// Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
     1264bool fglock = (_fgimgapp) ? false : true;
     1265
    11871266if (dr) {
    11881267  PIDrawer3D * dr3 = dynamic_cast<PIDrawer3D *>(dr);
    1189   if(dr3)  wrsid = myImgApp->Disp3DDrawer(dr3, n1, dopt);
    1190   else wrsid = myImgApp->DispScDrawer( dr, n1, dopt);
    1191   }
    1192 else if (arr) wrsid = myImgApp->DispImage(arr, n1, dopt);
     1268  if(dr3)  wrsid = myImgApp->Disp3DDrawer(dr3, n1, dopt, "", 0, fglock);
     1269  else wrsid = myImgApp->DispScDrawer( dr, n1, dopt, "", 0, fglock);
     1270  }
     1271else if (arr) wrsid = myImgApp->DispImage(arr, n1, dopt, 0, fglock);
    11931272
    11941273AddWRsId(nom, wrsid);
     
    11991278void NamedObjMgr::DisplayImage(string& nom, string dopt)
    12001279{
     1280ZSync(*myMutex);
     1281
    12011282NObjMgrAdapter* obja=NULL;
    12021283obja = GetObjAdapter(nom);
     
    12221303ParseObjectName(nom, r1, n1);
    12231304
     1305// Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
     1306bool fglock = (_fgimgapp) ? false : true;
     1307
    12241308int wrsid = 0;
    1225 wrsid = myImgApp->DispImage(arr, n1, dopt);
     1309wrsid = myImgApp->DispImage(arr, n1, dopt, 0, fglock);
    12261310
    12271311AddWRsId(nom, wrsid);
     
    12311315void NamedObjMgr::DisplaySurf3D(string& nom, string dopt)
    12321316{
     1317ZSync(*myMutex);
     1318
    12331319NObjMgrAdapter* obja=NULL;
    12341320obja = GetObjAdapter(nom);
     
    12611347ParseObjectName(nom, r1, n1);
    12621348
     1349// Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
     1350bool fglock = (_fgimgapp) ? false : true;
     1351
    12631352int wrsid = 0;
    12641353PISurfaceDrawer* sdr = new PISurfaceDrawer(arr, true, true, true);
    1265 wrsid = myImgApp->Disp3DDrawer(sdr, n1, dopt);
     1354wrsid = myImgApp->Disp3DDrawer(sdr, n1, dopt, "", 0, fglock);
    12661355AddWRsId(nom, wrsid);
    12671356return;
     
    12731362                            string& label, string dopt, bool fg3d)
    12741363{
     1364ZSync(*myMutex);
     1365
    12751366AnyDataObj* obj=GetObj(nom);
    12761367if (obj == NULL) {
     
    12931384string n1,r1;
    12941385ParseObjectName(nom, r1, n1);
     1386
     1387// Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
     1388bool fglock = (_fgimgapp) ? false : true;
    12951389
    12961390if ( fg3d && (nmz.length()>0) )  { // Display 3D
     
    13011395  pin->SelectErrBar(erx.c_str(), ery.c_str(), erz.c_str());
    13021396  string titre = nmz + "%" + nmy + "%" + nmz;
    1303   wrsid = myImgApp->Disp3DDrawer(pin, n1, dopt, titre); 
     1397  wrsid = myImgApp->Disp3DDrawer(pin, n1, dopt, titre, 0, fglock); 
    13041398}
    13051399else {
     
    13101404  pin->SelectErrBar(erx.c_str(), ery.c_str());
    13111405  string titre = nmy + "%" + nmx;
    1312   wrsid = myImgApp->DispScDrawer( (PIDrawer*)pin, n1, dopt, titre);
     1406  wrsid = myImgApp->DispScDrawer( (PIDrawer*)pin, n1, dopt, titre, 0, fglock);
    13131407  }
    13141408
     
    13311425//|  opt = options generales pour le display.
    13321426{
     1427ZSync(*myMutex);
     1428
    13331429AnyDataObj* obj=GetObj(nom);
    13341430if(obj == NULL)
     
    13561452 string n1,r1;
    13571453 ParseObjectName(nom, r1, n1);
     1454 // Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
     1455 bool fglock = (_fgimgapp) ? false : true;
    13581456
    13591457 int wrsid = 0;
     
    13621460  pigfd->SelectXY(numvx,numvy);
    13631461  pigfd->SelectErrBar(errx,erry,errz);
    1364   wrsid = myImgApp->Disp3DDrawer(pigfd,n1,dopt); 
     1462  wrsid = myImgApp->Disp3DDrawer(pigfd,n1,dopt,"",0,fglock); 
    13651463} else {                   // display 2D
    13661464  PIGenFitDat* pigfd = new PIGenFitDat(((GeneralFitData*)obj),false);
    13671465  pigfd->SelectX(numvx);
    13681466  pigfd->SelectErrBar(errx,erry);
    1369   wrsid = myImgApp->DispScDrawer((PIDrawer*)pigfd,n1,dopt);
     1467  wrsid = myImgApp->DispScDrawer((PIDrawer*)pigfd,n1,dopt,"",0,fglock);
    13701468}
    13711469
     
    13801478//   nomvx et nomvy
    13811479{
     1480ZSync(*myMutex);
     1481
    13821482#ifdef SANS_EVOLPLANCK
    13831483  cerr << " NamedObjMgr::DisplayVector() Error: Not implemented with PEIDA " << endl;
     
    14391539ParseObjectName(nomvy, ry, ny);
    14401540
     1541// Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
     1542bool fglock = (_fgimgapp) ? false : true;
     1543
    14411544string title = ny + " (Y) vs. " + nx + " (X)";
    14421545// display 2D
    1443 myImgApp->DispScDrawer(vxydrw, title, dopt);
     1546myImgApp->DispScDrawer(vxydrw, title, dopt, "", 0, fglock);
    14441547
    14451548return;
     
    14891592{
    14901593if (!myImgApp)  return;
     1594ZSync(*myMutex);
    14911595if ( !_fgimgapp )  ZSync(myImgApp->getMutex(),2);
    14921596
Note: See TracChangeset for help on using the changeset viewer.