Savarese Software Research Corporation
service/service.cc
Go to the documentation of this file.
00001 /*
00002  * Copyright 2009 Savarese Software Research 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  *     https://www.savarese.com/software/ApacheLicense-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 #include <ssrc/wispers/service/service.h>
00018 #include <ssrc/wispers/utility/BindProperties.h>
00019 #include <ssrc/wispers/utility/memusage.h>
00020 
00021 #include <algorithm>
00022 
00023 #include <unistd.h>
00024 #include <sys/resource.h>
00025 #include <sys/utsname.h>
00026 #include <sys/times.h>
00027 
00028 __BEGIN_NS_SSRC_WSPR_SERVICE
00029 
00030 #if defined(WISPERS_HAVE_GET_MEMUSAGE)
00031 using NS_SSRC_WSPR_UTILITY::memusage;
00032 using NS_SSRC_WSPR_UTILITY::get_memusage;
00033 using NS_SSRC_WSPR_UTILITY::BindProperties;
00034 #endif
00035 
00036 using NS_SSRC_WSPR_UTILITY::Properties;
00037 using NS_SSRC_WSPR_UTILITY::primitive_property_vector;
00038 
00039 properties_ptr ServiceProtocolProcessor::get_status() {
00040   properties_ptr props = properties_ptr(new Properties);
00041   Properties *status   = props->create_node("srv");
00042   const ::pid_t pid = ::getpid();
00043 
00044   status->set(_caller.name(), "name");
00045   status->set(::getuid(), "uid");
00046   status->set(::getgid(), "gid");
00047   status->set(::geteuid(), "euid");
00048   status->set(::getegid(), "egid");
00049   status->set(pid, "pid");
00050   status->set(context().count_timeouts(), "timeouts");
00051 
00052   ::tms cputime;
00053 
00054   if(::times(&cputime) != -1) {
00055     long result = ::sysconf(_SC_CLK_TCK);
00056     if(result > 0) {
00057       double ticks_per_second = static_cast<double>(result);
00058       status->set(static_cast<double>(cputime.tms_utime)/ticks_per_second,
00059                   "utime");
00060       status->set(static_cast<double>(cputime.tms_stime)/ticks_per_second,
00061                   "stime");
00062       status->set(static_cast<double>(cputime.tms_cutime)/ticks_per_second,
00063                   "cutime");
00064       status->set(static_cast<double>(cputime.tms_cstime)/ticks_per_second,
00065                   "cstime");
00066 
00067     }
00068   }
00069 
00070   primitive_property_vector & service_types =
00071     status->create_primitive_property_vector("types");
00072 
00073   for(service_type_iterator it = service_types_begin(),
00074         end = service_types_end(); it != end; ++it) {
00075     service_types.push_back(*it);
00076   }
00077 
00078   struct utsname u_name;
00079 
00080   if(::uname(&u_name) > -1) {
00081     Properties *node = props->create_node("node");
00082 
00083     node->set<string>(u_name.sysname, "sysname");
00084     node->set<string>(u_name.nodename, "nodename");
00085     node->set<string>(u_name.release, "release");
00086     node->set<string>(u_name.version, "version");
00087     node->set<string>(u_name.machine, "machine");
00088   }
00089 
00090 #if defined(WISPERS_HAVE_GET_MEMUSAGE)
00091   memusage musage;
00092 
00093   if(get_memusage(pid, musage)) {
00094     musage.visit(BindProperties(*status->create_node("memusage")));
00095   }
00096 #endif
00097 
00098   status = status->create_node("caller");
00099 
00100   status->set(_caller.initial_message_capacity(), "initial_message_capacity");
00101   status->set(_caller.message_capacity(), "message_capacity");
00102   status->set(_caller.request_queue_size(), "request_queue_size");
00103   status->set(_caller.response_map_size(), "response_map_size");
00104   status->set(_caller.count_jumbo_messages(), "jumbo_messages");
00105   status->set(_caller.group_membership(), "group_membership");
00106   status->set(_caller.continuations_map_size(), "continuations_map_size");
00107 
00108   return props;
00109 }
00110 
00111 void ServiceProtocolProcessor::process_request(const MessageStatusRequest & msg,
00112                                                const MessageInfo & msginfo)
00113 {
00114   _caller.send<CallStatusReply>(Message::FIFOSelfDiscard,
00115                                 msginfo.sender(), get_status());
00116 }
00117 
00118 __END_NS_SSRC_WSPR_SERVICE

Savarese Software Research Corporation
Copyright © 2006-2011 Savarese Software Research Corporation. All rights reserved.