startstop.cpp

This is an example of using <sm_vas.h>. It shows a minimal storage manager server, which does nothing but start up (recover) and shut down.

00001 /*<std-header orig-src='shore'>
00002 
00003  $Id: startstop.cpp,v 1.1 2010/05/26 01:21:21 nhall Exp $
00004 
00005 SHORE -- Scalable Heterogeneous Object REpository
00006 
00007 Copyright (c) 1994-99 Computer Sciences Department, University of
00008                       Wisconsin -- Madison
00009 All Rights Reserved.
00010 
00011 Permission to use, copy, modify and distribute this software and its
00012 documentation is hereby granted, provided that both the copyright
00013 notice and this permission notice appear in all copies of the
00014 software, derivative works or modified versions, and any portions
00015 thereof, and that both notices appear in supporting documentation.
00016 
00017 THE AUTHORS AND THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY
00018 OF WISCONSIN - MADISON ALLOW FREE USE OF THIS SOFTWARE IN ITS
00019 "AS IS" CONDITION, AND THEY DISCLAIM ANY LIABILITY OF ANY KIND
00020 FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
00021 
00022 This software was developed with support by the Advanced Research
00023 Project Agency, ARPA order number 018 (formerly 8230), monitored by
00024 the U.S. Army Research Laboratory under contract DAAB07-91-C-Q518.
00025 Further funding for this work was provided by DARPA through
00026 Rome Research Laboratory Contract No. F30602-97-2-0247.
00027 
00028 */
00029 
00030 /*  -- do not edit anything above this line --   </std-header>*/
00031 
00032 // This include brings in all header files needed for writing a VAs 
00033 //
00034 #include "sm_vas.h"
00035 
00036 /* This is about the most minimal storage manager program there is.
00037  * This starts up and shuts down a storage manager. 
00038  */
00039 
00040 
00041 /* smthread-based class for all sm-related work */
00042 class smthread_user_t : public smthread_t {
00043     int        argc;
00044     char       **argv;
00045 public:
00046     int        retval;
00047 
00048     smthread_user_t(int ac, char **av) 
00049             : smthread_t(t_regular, "smthread_user_t"),
00050             argc(ac), argv(av), retval(0) { }
00051     ~smthread_user_t()  {}
00052     void run() {
00053         cout << "Starting SSM and performing recovery ..." << endl;
00054         ss_m* ssm = new ss_m();
00055         if (!ssm) {
00056             cerr << "Error: Out of memory for ss_m" << endl;
00057             retval = 1;
00058             return;
00059         }
00060         /* DO WORK: 
00061          * Any other work with the storage manager should be
00062          * done here or in child threads forked by this one,
00063          * and passed this ss_m as an argument, then
00064          * AWAIT CHILDREN (via join)
00065          */
00066 
00067         delete ssm;
00068         ssm = NULL;
00069     }
00070 };
00071 
00072 
00073 int
00074 main(int argc, char* argv[])
00075 {
00076     /* the storage manager requires that certain options are set.
00077      * Get them from the file named EXAMPLE_SHORECONFIG
00078      */
00079     option_group_t options(3);// three levels.
00080     W_COERCE(options.add_class_level("startstop")); 
00081     W_COERCE(options.add_class_level("server"));    // server or client
00082     W_COERCE(options.add_class_level(argv[0])); // program name
00083     // Here add your options to this group.
00084 
00085     W_COERCE(ss_m::setup_options(&options));
00086     // adds the storage manager options to this group 
00087     
00088     {
00089         /* scan the file to get values for the options */
00090         /* Note that we could scan the command line also or instead: you
00091          * can find an example of this is src/sm/tests/options.cpp
00092          */
00093         w_ostrstream      err_stream;
00094         const char* opt_file = "EXAMPLE_SHORECONFIG";   // option config file
00095         option_file_scan_t opt_scan(opt_file, &options);
00096 
00097         // scan the file and override any current option settings
00098         // options names must be spelled correctly
00099         w_rc_t rc = opt_scan.scan(true /*override*/, err_stream, true);
00100         if (rc.is_error()) {
00101             cerr << "Error in reading option file: " << opt_file << endl;
00102             cerr << "\t" << err_stream.c_str() << endl;
00103             return 1;
00104         }
00105     }
00106     {
00107         /* check that all required options have been set */
00108         w_ostrstream      err_stream;
00109         w_rc_t rc = options.check_required(&err_stream);
00110         if (rc.is_error()) {
00111             cerr << "These required options are not set:" << endl;
00112             cerr << err_stream.c_str() << endl;
00113             return 1;
00114         }
00115     }
00116 
00117     /* GO */
00118     smthread_user_t *smtu = new smthread_user_t(argc, argv);
00119     if (!smtu)
00120             W_FATAL(fcOUTOFMEMORY);
00121 
00122     w_rc_t e = smtu->fork();
00123     if(e.is_error()) {
00124         cerr << "error forking thread: " << e <<endl;
00125         return 1;
00126     }
00127     e = smtu->join();
00128     if(e.is_error()) {
00129         cerr << "error forking thread: " << e <<endl;
00130         return 1;
00131     }
00132     int        rv = smtu->retval;
00133     delete smtu;
00134     return rv;
00135 }
00136 

Generated on Wed Jul 7 17:22:31 2010 for Shore Storage Manager by  doxygen 1.4.7