cdiISTest.cxx

00001 
00003 //    create_info.cc
00004 //
00005 //    Test application for the IS library
00006 //
00007 //    Sergei Kolos,  January 2002
00008 //
00009 //    description:
00010 //          Test the functionality of the ISNamedInfo class
00011 //      
00013 
00014 #include <iostream>
00015 #include "ipc/core.h"
00016 #include <ipc/partition.h>
00017 #include "cdi/Conditions.h"
00018 #include <unistd.h>
00019 
00020 int main(int argc, char ** argv)
00021 {
00022   IPCCore::init( argc, argv );
00023   
00024   std::cout << OWLTime() << " :: cdiISTest is initializing!" << std::endl;
00025   std::cout << OWLTime() << " :: cdiISTest -> Initializing partition [be_test]!" << std::endl;
00026   IPCPartition      p("be_test");
00027 
00028   std::cout << OWLTime() << " :: cdiISTest -> Initializing the dictionary!" << std::endl;
00029   ISInfoDictionary dict(p); 
00030   
00031   std::cout << OWLTime() << " :: cdiISTest -> Initializing Conditions object!" << std::endl;
00032   Conditions c;
00033   
00034   std::vector<std::string> a;
00035 
00036   std::cout << OWLTime() << " :: cdiISTest -> Adding Information objects to the list!" << std::endl;
00037   a.push_back("RunCtrl.Application_dsa_supervisor");
00038   a.push_back("RunEvents.*");
00039   a.push_back("RunParams.RunParams");
00040   a.push_back("RunParams.Conditions");
00041 
00042 
00043 
00044   /*
00045     std::string *a = new std::string[3];
00046     
00047     a[0] = "RunCtrl.Application_dsa_supervisor";  
00048     a[1]  = "RunEvents.*";
00049     
00050     a[2] ="RunParams.RunParams";
00051     
00052   */
00053   
00054   // define the information about the Conditions
00055   c.ISServers_size = 4;
00056   c.ISServers = a;
00057   
00058   //c.ISServers = new std::string("RunParams.RunParams");
00059   
00060   std::cout << OWLTime() << " :: cdiISTest -> subscribing the servers to the dictionary!" << std::endl;
00061   dict.insert("MyServer.Conditions", c);
00062   
00063   
00064   //c.ISServers = new std::string("RunCtr.RunCtrl");
00065   
00066   // let's create multiple threads to submit data
00067   int pid; /* alias: pid_t pid; */
00068   int pid2;
00069   pid = fork(); /* the familiar kitchenware! */
00070   
00071   if (pid == -1) {
00072     std::cerr << OWLTime() << " :: cdiISTest failed to create multiple threads!" << std::endl;
00073     exit(1);
00074   } /* fork() returns -1 on error, and much knownigly sets the global errno variable */
00075   
00076   if (pid != 0) {
00077     std::cout << OWLTime() << " :: cdiISTest -> Main thread executing: PID: [" << getpid() << "]!" << std::endl;
00078     std::cout << OWLTime() << " :: cdiISTest -> Forking again the execution" << std::endl;
00079     
00080     pid2 = fork();
00081 
00082     if (pid2 == -1) {
00083       std::cerr << OWLTime() << " :: cdiISTest failed to create multiple threads!" << std::endl;
00084       exit(1);
00085     }
00086     
00087     // this is the main thread...it'll update information to the IS
00088     if (pid != 0) {
00089       
00090       while(1){
00091     //a[0]="RunParams.RunParams";
00092     //a[1] = "Ola";
00093     //c.ISServers_size = 2;
00094     //c.ISServers = a;
00095     dict.update ("MyServer.Conditions", c);
00096     sleep(5);
00097       }
00098     }
00099 
00100   } /* if the value returned is non zero and not -1, then this is the parent process */
00101   printf("\n\n\tWe love Unix!\n\n"); /* this is a common task for both processes */
00102   if (pid == 0) {
00103     printf("Hello World, my name is GoogooGaga!\n");
00104     printf("My process id is %d\n", getpid());
00105     printf("I have ONE papa (ofcourse), his name is Pappy, and has a process id %d\n", getppid());
00106   } /* if the returned value is 0 then you're the child process */
00107   exit(0);
00108 
00109 
00110   while(1){
00111     //a[0]="RunParams.RunParams";
00112     //a[1] = "Ola";
00113     //c.ISServers_size = 2;
00114     //c.ISServers = a;
00115     dict.update ("MyServer.Conditions", c);
00116     sleep(5);
00117   }
00118   
00119   return 0;
00120 }

Generated on Mon Feb 6 14:01:17 2006 for SCT DAQ/DCS Software - C++ by  doxygen 1.4.6