00001
00002
00003 #include "CountedExample.h"
00004 #include <ipc/core.h>
00005 #include <unistd.h>
00006 #include <iostream>
00007
00008 void sl(const unsigned int s) {
00009 std::cout << "Sleeping for " << s << " seconds" << std::endl;
00010 sleep(s);
00011 };
00012
00013 void createACountedExampleAndDoStuff() {
00014 std::cout << "Making a CountedExample ..." << std::endl;
00015 CountedExample & countedExampleSrv = *(new CountedExample);
00016 std::cout << "... finishing making a CountedExample" << std::endl;
00017 sl(1);
00018 {
00019
00020 std::cout << "Getting a reference to the countedExample object" << std::endl;
00021 Stew::CountedExample_var countedExampleRef = countedExampleSrv._this();
00022 sl(1);
00023 };
00024
00025 {
00026
00027 std::cout << "Getting a different reference to the countedExample object" << std::endl;
00028 Stew::CountedExample_var countedExampleRef = countedExampleSrv._this();
00029 sl(1);
00030
00031 std::cout << "Decrementing the count on the second reference ... should lead to the death of the servant" << std::endl;
00032 countedExampleRef->removeRef();
00033
00034 sl(1);
00035
00036 };
00037
00038 };
00039
00040 int main(int argc, char * argv[]) {
00041 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, and where the lifetime of the servant managing this object is to be controlled by the user manually via calls to addCount() and removeCount(). This makes it a little bit like an \"unsafe\" boost::shared_ptr." << std::endl;
00042 std::cout << "Initialising IPC ..." << std::endl;
00043 IPCCore::init(argc, argv);
00044
00045
00046 createACountedExampleAndDoStuff();
00047
00048 std::cout << "Bye" << std::endl;
00049 };