Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Related Pages

mainForTemporaryReturnType.cpp

00001 
00002 
00003 #include "LargeTemporaryReturnType.h"
00004 #include <ipc/core.h>
00005 #include <unistd.h>
00006 
00007 void sl(const unsigned int s) {
00008     std::cout << "Sleeping for " << s << " seconds" << std::endl;
00009     sleep(s);
00010 };
00011 
00012 void createATemporaryReturnTypeAndDoStuff() {
00013   std::cout << "Making a temporaryreturntype ..." << std::endl;
00014   LargeTemporaryReturnType & largeTemporaryReturnType = *(new LargeTemporaryReturnType); // not supposed to do "LargeCarrot largeCarrot;" as this can lead to largeCarrot being deleted twice -- once when largeCarrot goes out of scope, and once if/when someone remotely requests it be deleted.".  For this reason, we are equally only supposed to delete it with _destroy();
00015   std::cout << "... finishing making a temporaryreturntype" << std::endl;
00016   sl(1);
00017   {
00018     // get a reference to the temporaryreturntype object
00019     std::cout << "Getting a reference to the temporaryreturntype object" << std::endl;
00020     Stew::TemporaryReturnType_var temporaryreturntype = largeTemporaryReturnType._this();
00021     sl(1);
00022   };
00023 
00024   {
00025     // get a different reference to the temporaryreturntype object
00026     std::cout << "Getting a different reference to the temporaryreturntype object" << std::endl;
00027     Stew::TemporaryReturnType_var temporaryreturntype = largeTemporaryReturnType._this();
00028     sl(1);
00029 
00030     std::cout << "Calling endLifeOfServant on the reference" << std::endl;
00031     temporaryreturntype->deleteServant(); // we implemented this method so that it would end the life of the servant.
00032     // it is vital we call shutdown for this temporary object otherwise we will leak memory.
00033     sl(1);
00034   };
00035   
00036 };
00037 
00038 int main(int argc, char * argv[]) {
00039   std::cout << "This program demonstrates how to use an object that will live only for a short time (eg a return type) that will not be published in the IPC::Partition index." << std::endl;
00040   std::cout << "Initialising IPC ..." << std::endl;
00041   IPCCore::init(argc, argv);
00042 
00043   // create the server for a TemporaryReturnType object
00044   createATemporaryReturnTypeAndDoStuff();
00045 
00046   std::cout << "Bye" << std::endl;
00047 };

Generated on Fri Sep 16 18:01:52 2005 for SCT DAQ/DCS Software - C++ by doxygen 1.3.5