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 ServiceReplyHandlerMethod.hpp 00024 * @Description ServiceReplyHandlerMethod 00025 * @Status Work in Progress 00026 * @Version $Id: ServiceReplyHandlerMethod.hpp 1 2011-03-04 18:13:18Z jreis $ 00027 * @Maintainer Marco Barbosa 00028 */ 00029 00030 #ifndef __SERVICE_SERVICEREPLYHANDLERMETHOD_H 00031 #define __SERVICE_SERVICEREPLYHANDLERMETHOD_H 00032 00033 #include <ServiceReply.hpp> 00034 00035 00036 00037 00038 namespace mermaid 00039 { 00040 namespace support 00041 { 00042 namespace service 00043 { 00044 00045 using boost::shared_ptr; 00046 00047 /** 00048 * @Class ServiceIReplyHandlerMethodBase ServiceReplyHandlerMethod.hpp "ServiceReplyHandlerMethod.hpp" 00049 * @Description Base class for all ServiceReplyHandlerMethod objects. 00050 * 00051 * This class is needed in order to call ServiceReplyHandlerMethod without having to know the specific class used by the template. 00052 * @Author Marco Barbosa 00053 */ 00054 class ServiceReplyHandlerMethodBase 00055 { 00056 public: 00057 /** 00058 * @Description Handler call method. 00059 * 00060 * This method calls the handler to which the instance of this class points to. 00061 * @Author Marco Barbosa 00062 */ 00063 virtual void callHandler (shared_ptr<ServiceReply> reply) = 0; 00064 }; 00065 00066 00067 /** 00068 * @Class ServiceInterfaceHandlerMethod ServiceInterfaceHandlerMethod.hpp "ServiceInterfaceHandlerMethod.hpp" 00069 * @Description Class that stores a pointer to a method of an object. It holds a pointer to a method suitable for handling service requests. 00070 * @Author Marco Barbosa 00071 */ 00072 template <class o> 00073 class ServiceReplyHandlerMethod : public ServiceReplyHandlerMethodBase 00074 { 00075 typedef void (o::*SERVICE_REPLY_HANDLER_METHOD) (shared_ptr<ServiceReply> reply); 00076 public: 00077 /** 00078 * @Description Contstructor. 00079 * @Argument object Object instance on which the method shall be called 00080 * @Argument method Method of the object's class 00081 */ 00082 ServiceReplyHandlerMethod (o * object, SERVICE_REPLY_HANDLER_METHOD method) { 00083 object_ = object; 00084 method_ = method; 00085 } 00086 00087 /** 00088 * @Description Method call 00089 * @Argument dataBox DataBox containing the input data. 00090 */ 00091 virtual void callHandler (shared_ptr<ServiceReply> reply) { 00092 (object_->*method_) (reply); 00093 } 00094 00095 private: 00096 o * object_; 00097 SERVICE_REPLY_HANDLER_METHOD method_; 00098 }; // class ServiceReplyHandlerMethod 00099 } // namespace service 00100 } // namespace support 00101 } // namespace mermaid 00102 00103 #endif // __SERVICE_SERVICEREPLYHANDLERMETHOD_H