servlib/cmd/BPQCommand.cc
changeset 66 e1101c5d54a1
child 67 cfe2328ba1c6
equal deleted inserted replaced
65:333724f2f7cf 66:e1101c5d54a1
       
     1 /*
       
     2  *    Copyright 2011 Trinity College Dublin
       
     3  * 
       
     4  *    Licensed under the Apache License, Version 2.0 (the "License");
       
     5  *    you may not use this file except in compliance with the License.
       
     6  *    You may obtain a copy of the License at
       
     7  * 
       
     8  *        http://www.apache.org/licenses/LICENSE-2.0
       
     9  * 
       
    10  *    Unless required by applicable law or agreed to in writing, software
       
    11  *    distributed under the License is distributed on an "AS IS" BASIS,
       
    12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       
    13  *    See the License for the specific language governing permissions and
       
    14  *    limitations under the License.
       
    15  */
       
    16 
       
    17 #ifdef HAVE_CONFIG_H
       
    18 #  include <dtn-config.h>
       
    19 #endif
       
    20 
       
    21 #include "BPQCommand.h"
       
    22 #include "bundling/BundleDaemon.h"
       
    23 
       
    24 namespace dtn {
       
    25 
       
    26 BPQCommand::BPQCommand()
       
    27 	: TclCommand("bpq")
       
    28 {
       
    29 	add_to_help("enabled", "enable BPQ cache");
       
    30 	add_to_help("cache_size <size>", "set BPQ cache size");
       
    31 }
       
    32 
       
    33 int
       
    34 BPQCommand::exec(int argc, const char** argv, Tcl_Interp* interp)
       
    35 {
       
    36 	(void)interp;
       
    37     // need a subcommand
       
    38     if (argc < 2) {
       
    39         wrong_num_args(argc, argv, 1, 2, INT_MAX);
       
    40         return TCL_ERROR;
       
    41     }
       
    42     const char* op = argv[1];
       
    43 
       
    44     if (strncmp(op, "enabled", strlen("enabled")) == 0) {
       
    45 
       
    46 		BundleDaemon::instance()->bpq_cache()->cache_enabled_ = true;
       
    47 		return TCL_OK;
       
    48 
       
    49     } else if(strncmp(op, "cache_size", strlen("cache_size")) == 0) {
       
    50         if (argc < 3) {
       
    51             wrong_num_args(argc, argv, 2, 3, INT_MAX);
       
    52             return TCL_ERROR;
       
    53         }
       
    54 
       
    55         const char* size_str = argv[2];
       
    56 		u_int size = atoi(size_str);
       
    57 
       
    58 		BundleDaemon::instance()->bpq_cache()->max_cache_size_ = size;
       
    59 		return TCL_OK;
       
    60     }
       
    61 
       
    62     resultf("invalid bpq subcommand '%s'", op);
       
    63     return TCL_ERROR;
       
    64 }
       
    65 
       
    66 } // namespace dtn