59static TObject*
FollowPath(TObject* container,
char* path)
64 printf(
"Follow path [%s] in container %p\n", path, container);
69 char* s = strchr(path,
'/');
76 if (container->InheritsFrom(TDirectory::Class()))
77 obj = ((
TDirectory*)container)->FindObject(path);
78 else if (container->InheritsFrom(TFolder::Class()))
79 obj = ((TFolder*)container)->FindObject(path);
80 else if (container->InheritsFrom(TCollection::Class()))
81 obj = ((TCollection*)container)->FindObject(path);
84 printf(
"ERROR: Container \'%s\' of type %s is not a TDirectory, TFolder or TCollection\n", container->GetName(), container->IsA()->GetName());
210 xfile =
new TFile(
"/dev/null");
212 TClass *xclass = obj->IsA();
214 if (xclass->InheritsFrom(TDirectory::Class()))
215 xclass = TDirectory::Class();
216 else if (xclass->InheritsFrom(TFolder::Class()))
217 xclass = TDirectory::Class();
218 else if (xclass->InheritsFrom(TCollection::Class()))
219 xclass = TDirectory::Class();
222 name = obj->GetName();
225 return new TKey(name, obj->GetTitle(), xclass, 0, xfile);
237 TSocket *sock = (TSocket *) arg;
238 TMessage message(kMESS_OBJECT);
243 int rd = sock->Recv(request,
sizeof(request));
247 fprintf(stderr,
"TNetDirectory connection from %s closed\n", sock->GetInetAddress().GetHostName());
254 printf(
"Request [%s] from %s\n", request, sock->GetInetAddress().GetHostName());
256 if (strcmp(request,
"GetListOfKeys") == 0)
263 TList* keys =
new TList();
265 for (
unsigned int i=0; i<
gExports.size(); i++)
267 const char* ename =
gExports[i].c_str();
274 fprintf(stderr,
"GetListOfKeys: Exported name \'%s\' cannot be found!\n", xname);
278 TKey* key =
MakeKey(obj, 1, gROOT, ename);
284 printf(
"Sending keys %p\n", keys);
288 message.Reset(kMESS_OBJECT);
289 message.WriteObject(keys);
294 else if (strncmp(request,
"GetListOfKeys ", 14) == 0)
298 char* dirname = request + 14;
302 if (obj && obj->InheritsFrom(TDirectory::Class()))
325 TObject *obj = next();
332 const char* name = obj->GetName();
334 if (!keys->FindObject(name))
336 TKey* key =
MakeKey(obj, 1, dir);
344 message.Reset(kMESS_OBJECT);
345 message.WriteObject(keys);
349 else if (obj && obj->InheritsFrom(TFolder::Class()))
351 TFolder* folder = (TFolder*)obj;
356 TIterator *iterator = folder->GetListOfFolders()->MakeIterator();
358 TList* keys =
new TList();
366 const char* name = obj->GetName();
368 if (!keys->FindObject(name))
370 TKey* key =
MakeKey(obj, 1, gROOT);
379 printf(
"Sending keys %p\n", keys);
383 message.Reset(kMESS_OBJECT);
384 message.WriteObject(keys);
387 else if (obj && obj->InheritsFrom(TCollection::Class()))
389 TCollection* collection = (TCollection*)obj;
394 TIterator *iterator = collection->MakeIterator();
396 TList* keys =
new TList();
404 const char* name = obj->GetName();
406 if (!keys->FindObject(name))
408 TKey* key =
MakeKey(obj, 1, gROOT);
417 printf(
"Sending keys %p\n", keys);
421 message.Reset(kMESS_OBJECT);
422 message.WriteObject(keys);
427 fprintf(stderr,
"netDirectoryServer: ERROR: obj %p name %s, type %s is not a directory!\n", obj, obj->GetName(), obj->IsA()->GetName());
428 TObjString s(
"Not a directory");
429 message.Reset(kMESS_OBJECT);
430 message.WriteObject(&s);
434 fprintf(stderr,
"netDirectoryServer: ERROR: obj %p not found\n", obj);
435 TObjString s(
"Not found");
436 message.Reset(kMESS_OBJECT);
437 message.WriteObject(&s);
443 else if (strncmp(request,
"FindObjectByName ", 17) == 0)
447 char* top = request + 17;
459 sprintf(str,
"TDirectory %s", obj->GetName());
461 for (
unsigned int i=0; i<
gExports.size(); i++)
463 const char* ename =
gExports[i].c_str();
466 if (strcmp(xname, obj->GetName()) == 0)
468 sprintf(str,
"TDirectory %s", ename);
473 obj =
new TObjString(str);
480 if (obj && obj->InheritsFrom(TDirectory::Class()))
483 sprintf(str,
"TDirectory %s", obj->GetName());
484 obj =
new TObjString(str);
487 if (obj && obj->InheritsFrom(TFolder::Class()))
490 sprintf(str,
"TDirectory %s", obj->GetName());
491 obj =
new TObjString(str);
494 if (obj && obj->InheritsFrom(TCollection::Class()))
497 sprintf(str,
"TDirectory %s", obj->GetName());
498 obj =
new TObjString(str);
504 printf(
"Sending object %p name \'%s\' class \'%s\'\n", obj, obj->GetName(), obj->IsA()->GetName());
506 printf(
"Sending object %p\n", obj);
510 message.Reset(kMESS_OBJECT);
511 message.WriteObject(obj);
515 else if (strncmp(request,
"ResetTH1 ", 9) == 0)
519 char* path = request + 9;
521 if (strlen(path) > 1)
530 for (
unsigned int i=0; i<
gExports.size(); i++)
532 const char* ename =
gExports[i].c_str();
539 fprintf(stderr,
"ResetTH1: Exported name \'%s\' cannot be found!\n", xname);
547 TObjString s(
"Success");
549 message.Reset(kMESS_OBJECT);
550 message.WriteObject(&s);
556 fprintf(stderr,
"netDirectoryServer: Received unknown request \"%s\"\n", request);
558 TObjString s(
"Unknown request");
559 message.Reset(kMESS_OBJECT);
560 message.WriteObject(&s);
576 int port = *(
int *) arg;
578 fprintf(stderr,
"NetDirectory server listening on port %d...\n", port);
579 TServerSocket *lsock =
new TServerSocket(port, kTRUE);
583 TSocket *sock = lsock->Accept();
587 printf(
"TNetDirectory server accept() error\n");
592 fprintf(stderr,
"TNetDirectory connection from %s\n", sock->GetInetAddress().GetHostName());
598 LPDWORD lpThreadId = 0;
657 printf(
"Export TCollection %p named [%s] of type [%s] as [%s]\n", collection, collection->GetName(), collection->IsA()->GetName(), exportName);
660 for (
unsigned int i=0; i<
gExports.size(); i++)
662 const char* ename =
gExports[i].c_str();
663 if (strcmp(ename, exportName) == 0)