Web Wispers 1.2.2 C++ Unit Test Coverage
Current view: top level - ssrc/wispers/service - service.cc (source / functions) Hit Total Coverage
Test: Web Wispers 1.2.2 C++ Unit Tests Lines: 45 46 97.8 %
Date: 2012-04-09 Functions: 10 11 90.9 %
Branches: 89 188 47.3 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright 2009 Savarese Software Research Corporation
       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                 :            :  *     https://www.savarese.com/software/ApacheLicense-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                 :            : #include <ssrc/wispers/service/service.h>
      18                 :            : #include <ssrc/wispers/utility/BindProperties.h>
      19                 :            : #include <ssrc/wispers/utility/memusage.h>
      20                 :            : 
      21                 :            : #include <algorithm>
      22                 :            : 
      23                 :            : #include <unistd.h>
      24                 :            : #include <sys/resource.h>
      25                 :            : #include <sys/utsname.h>
      26                 :            : #include <sys/times.h>
      27                 :            : 
      28                 :            : __BEGIN_NS_SSRC_WSPR_SERVICE
      29                 :            : 
      30                 :            : #if defined(WISPERS_HAVE_GET_MEMUSAGE)
      31                 :            : using NS_SSRC_WSPR_UTILITY::memusage;
      32                 :            : using NS_SSRC_WSPR_UTILITY::get_memusage;
      33                 :            : using NS_SSRC_WSPR_UTILITY::BindProperties;
      34                 :            : #endif
      35                 :            : 
      36                 :            : using NS_SSRC_WSPR_UTILITY::Properties;
      37                 :            : using NS_SSRC_WSPR_UTILITY::primitive_property_vector;
      38                 :            : 
      39                 :          1 : properties_ptr ServiceProtocolProcessor::get_status() {
      40   [ +  -  +  - ]:          1 :   properties_ptr props = properties_ptr(new Properties);
      41   [ +  -  +  -  :          1 :   Properties *status   = props->create_node("srv");
                   +  - ]
      42         [ +  - ]:          1 :   const ::pid_t pid = ::getpid();
      43                 :            : 
      44   [ +  -  +  -  :          1 :   status->set(_caller.name(), "name");
                   +  - ]
      45   [ +  -  +  - ]:          1 :   status->set(::getuid(), "uid");
      46   [ +  -  +  - ]:          1 :   status->set(::getgid(), "gid");
      47   [ +  -  +  - ]:          1 :   status->set(::geteuid(), "euid");
      48   [ +  -  +  - ]:          1 :   status->set(::getegid(), "egid");
      49         [ +  - ]:          1 :   status->set(pid, "pid");
      50   [ +  -  +  - ]:          1 :   status->set(context().count_timeouts(), "timeouts");
      51                 :            : 
      52                 :            :   ::tms cputime;
      53                 :            : 
      54   [ +  -  +  - ]:          1 :   if(::times(&cputime) != -1) {
      55         [ +  - ]:          1 :     long result = ::sysconf(_SC_CLK_TCK);
      56         [ +  - ]:          1 :     if(result > 0) {
      57                 :          1 :       double ticks_per_second = static_cast<double>(result);
      58                 :            :       status->set(static_cast<double>(cputime.tms_utime)/ticks_per_second,
      59         [ +  - ]:          1 :                   "utime");
      60                 :            :       status->set(static_cast<double>(cputime.tms_stime)/ticks_per_second,
      61         [ +  - ]:          1 :                   "stime");
      62                 :            :       status->set(static_cast<double>(cputime.tms_cutime)/ticks_per_second,
      63         [ +  - ]:          1 :                   "cutime");
      64                 :            :       status->set(static_cast<double>(cputime.tms_cstime)/ticks_per_second,
      65         [ +  - ]:          1 :                   "cstime");
      66                 :            : 
      67                 :            :     }
      68                 :            :   }
      69                 :            : 
      70                 :            :   primitive_property_vector & service_types =
      71         [ +  - ]:          1 :     status->create_primitive_property_vector("types");
      72                 :            : 
      73   [ +  -  #  #  :          2 :   for(service_type_iterator it = service_types_begin(),
             +  -  -  + ]
      74         [ +  - ]:          1 :         end = service_types_end(); it != end; ++it) {
      75   [ #  #  #  #  :          0 :     service_types.push_back(*it);
             #  #  #  # ]
      76                 :            :   }
      77                 :            : 
      78                 :            :   struct utsname u_name;
      79                 :            : 
      80   [ +  -  +  - ]:          1 :   if(::uname(&u_name) > -1) {
      81   [ +  -  +  -  :          1 :     Properties *node = props->create_node("node");
                   +  - ]
      82                 :            : 
      83   [ +  -  +  -  :          1 :     node->set<string>(u_name.sysname, "sysname");
                   +  - ]
      84   [ +  -  +  -  :          1 :     node->set<string>(u_name.nodename, "nodename");
                   +  - ]
      85   [ +  -  +  -  :          1 :     node->set<string>(u_name.release, "release");
                   +  - ]
      86   [ +  -  +  -  :          1 :     node->set<string>(u_name.version, "version");
                   +  - ]
      87   [ +  -  +  -  :          1 :     node->set<string>(u_name.machine, "machine");
                   +  - ]
      88                 :            :   }
      89                 :            : 
      90                 :            : #if defined(WISPERS_HAVE_GET_MEMUSAGE)
      91                 :          1 :   memusage musage;
      92                 :            : 
      93   [ +  -  +  - ]:          1 :   if(get_memusage(pid, musage)) {
      94   [ +  -  +  -  :          1 :     musage.visit(BindProperties(*status->create_node("memusage")));
             +  -  +  - ]
      95                 :            :   }
      96                 :            : #endif
      97                 :            : 
      98   [ +  -  +  -  :          1 :   status = status->create_node("caller");
                   +  - ]
      99                 :            : 
     100         [ +  - ]:          1 :   status->set(_caller.initial_message_capacity(), "initial_message_capacity");
     101   [ +  -  +  - ]:          1 :   status->set(_caller.message_capacity(), "message_capacity");
     102   [ +  -  +  - ]:          1 :   status->set(_caller.request_queue_size(), "request_queue_size");
     103   [ +  -  +  - ]:          1 :   status->set(_caller.response_map_size(), "response_map_size");
     104   [ +  -  +  - ]:          1 :   status->set(_caller.count_jumbo_messages(), "jumbo_messages");
     105         [ +  - ]:          1 :   status->set(_caller.group_membership(), "group_membership");
     106   [ +  -  +  - ]:          1 :   status->set(_caller.continuations_map_size(), "continuations_map_size");
     107                 :            : 
     108                 :          1 :   return props;
     109                 :            : }
     110                 :            : 
     111                 :          1 : void ServiceProtocolProcessor::process_request(const MessageStatusRequest & msg,
     112                 :            :                                                const MessageInfo & msginfo)
     113                 :            : {
     114                 :            :   _caller.send<CallStatusReply>(Message::FIFOSelfDiscard,
     115         [ +  - ]:          1 :                                 msginfo.sender(), get_status());
     116                 :          1 : }
     117                 :            : 
     118   [ +  -  +  -  :         75 : __END_NS_SSRC_WSPR_SERVICE
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  +  - ]