ShutdownCommand.cc

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2004-2006 Intel Corporation
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
00015  */
00016 
00017 
00018 #include "ShutdownCommand.h"
00019 #include "CompletionNotifier.h"
00020 #include "DTNServer.h"
00021 #include "bundling/BundleDaemon.h"
00022 
00023 namespace dtn {
00024 
00025 ShutdownCommand::ShutdownCommand(DTNServer* dtnserver, const char* cmd)
00026     : TclCommand(cmd), dtnserver_(dtnserver)
00027 {
00028     add_to_help(cmd, "shutdown the daemon");
00029 }
00030 
00031 void
00032 ShutdownCommand::call_exit(void* clientData)
00033 {
00034     (void)clientData;
00035     oasys::TclCommandInterp::instance()->exit_event_loop();
00036 }
00037 
00038 int
00039 ShutdownCommand::exec(int argc, const char** argv, Tcl_Interp* interp)
00040 {
00041     (void)interp;
00042 
00043     // should have no subcommands or options
00044     if (argc != 1) {
00045         wrong_num_args(argc, argv, 1, 1, 1);
00046         return TCL_ERROR;
00047     }
00048 
00049     // to make it possible to both return from the shutdown command
00050     // and still cleanly return from the tcl command, we exit from the
00051     // event loop in the background
00052     Tcl_CreateTimerHandler(0, ShutdownCommand::call_exit,
00053                            (void*)dtnserver_);
00054 
00055     return TCL_OK;
00056 }
00057 
00058 
00059 } // namespace dtn

Generated on Sat Sep 8 08:43:33 2007 for DTN Reference Implementation by  doxygen 1.5.3