00001 /* 00002 Copyright 2007, 2008, 2009, 2010, 2011 Instituto de Sistemas e Robotica, Instituto Superior Tecnico 00003 00004 This file is part of MeRMaID. 00005 00006 MeRMaID is free software: you can redistribute it and/or modify 00007 it under the terms of the GNU Lesser General Public License as published by 00008 the Free Software Foundation, either version 3 of the License, or 00009 (at your option) any later version. 00010 00011 MeRMaID is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU Lesser General Public License for more details. 00015 00016 You should have received a copy of the GNU Lesser General Public License 00017 along with MeRMaID. If not, see <http://www.gnu.org/licenses/>. 00018 */ 00019 00020 00021 00022 /** 00023 * @Filename ServiceInterfaceHandlerMethod.hpp 00024 * @Description ServiceInterfaceHandlerMethod 00025 * @Status Work in Progress 00026 * @Version $Id: ServiceInterfaceHandlerMethod.hpp 1 2011-03-04 18:13:18Z jreis $ 00027 * @Maintainer Marco Barbosa 00028 */ 00029 00030 #ifndef __SERVICE_SERVICEINTERFACEHANDLERMETHOD_H 00031 #define __SERVICE_SERVICEINTERFACEHANDLERMETHOD_H 00032 00033 #include <ServiceRequest.hpp> 00034 #include <ServiceReply.hpp> 00035 00036 00037 00038 00039 namespace mermaid 00040 { 00041 namespace support 00042 { 00043 namespace service 00044 { 00045 00046 using boost::shared_ptr; 00047 00048 /** 00049 * @Class ServiceInterfaceHandlerMethodBase ServiceInterfaceHandlerMethod.hpp "ServiceInterfaceHandlerMethod.hpp" 00050 * @Description Base class for all ServiceInterfaceHandlerMethod objects. 00051 * 00052 * This class is needed in order to call ServiceInterfaceHandlerMethod without having to know the specific class used by the template. 00053 * @Author Marco Barbosa 00054 */ 00055 class ServiceInterfaceHandlerMethodBase 00056 { 00057 public: 00058 /** 00059 * @Description Handler call method. 00060 * 00061 * This method calls the handler to which the instance of this class points to. 00062 * @Author Marco Barbosa 00063 */ 00064 virtual void callHandler (shared_ptr<ServiceRequest> request, shared_ptr<ServiceReply> reply) = 0; 00065 }; 00066 00067 00068 /** 00069 * @Class ServiceInterfaceHandlerMethod ServiceInterfaceHandlerMethod.hpp "ServiceInterfaceHandlerMethod.hpp" 00070 * @Description Class that stores a pointer to a method of an object. It holds a pointer to a method suitable for handling service requests. 00071 * @Author Marco Barbosa 00072 */ 00073 template <class o> 00074 class ServiceInterfaceHandlerMethod : public ServiceInterfaceHandlerMethodBase 00075 { 00076 typedef void (o::*SERVICE_INTERFACE_HANDLER_METHOD) (shared_ptr<ServiceRequest> request, shared_ptr<ServiceReply> reply); 00077 public: 00078 /** 00079 * @Description Contstructor. 00080 * @Argument object Object instance on which the method shall be called 00081 * @Argument method Method of the object's class 00082 */ 00083 ServiceInterfaceHandlerMethod (o * object, SERVICE_INTERFACE_HANDLER_METHOD method) { 00084 object_ = object; 00085 method_ = method; 00086 } 00087 00088 /** 00089 * @Description Method call 00090 * @Argument dataBox DataBox containing the input data. 00091 */ 00092 virtual void callHandler (shared_ptr<ServiceRequest> request, shared_ptr<ServiceReply> reply) { 00093 (object_->*method_) (request, reply); 00094 } 00095 00096 private: 00097 o * object_; 00098 SERVICE_INTERFACE_HANDLER_METHOD method_; 00099 }; // class ServiceInterfaceHandlerMethod 00100 } // namespace service 00101 } // namespace support 00102 } // namespace mermaid 00103 00104 #endif // __SERVICE_SERVICEINTERFACEHANDLERMETHOD_H