LogCabin
RPC/Service.h
Go to the documentation of this file.
00001 /* Copyright (c) 2012 Stanford University
00002  *
00003  * Permission to use, copy, modify, and distribute this software for any
00004  * purpose with or without fee is hereby granted, provided that the above
00005  * copyright notice and this permission notice appear in all copies.
00006  *
00007  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR(S) DISCLAIM ALL WARRANTIES
00008  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
00009  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL AUTHORS BE LIABLE FOR
00010  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00011  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00012  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
00013  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00014  */
00015 
00016 #ifndef LOGCABIN_RPC_SERVICE_H
00017 #define LOGCABIN_RPC_SERVICE_H
00018 
00019 namespace LogCabin {
00020 namespace RPC {
00021 
00022 // forward declaration
00023 class ServerRPC;
00024 
00025 /**
00026  * Base class for RPC services.
00027  * Each service handles a related set of RPCs from clients.
00028  */
00029 class Service {
00030   public:
00031     /**
00032      * Constructor.
00033      */
00034     Service() {}
00035 
00036     /**
00037      * Destructor.
00038      */
00039     virtual ~Service() {}
00040 
00041     /**
00042      * This method is overridden by a subclass and invoked by the Server class
00043      * when a new RPC arrives. It should call ServerRPC::reply() or another
00044      * method on the RPC to handle the request. The Server class calls this on
00045      * a thread pool.
00046      */
00047     virtual void handleRPC(ServerRPC serverRPC) = 0;
00048 
00049     /**
00050      * Return a short name for this service which can be used in things like
00051      * log messages.
00052      */
00053     virtual std::string getName() const = 0;
00054 
00055     // Service is non-copyable.
00056     Service(const Service&) = delete;
00057     Service& operator=(const Service&) = delete;
00058 }; // class Service
00059 
00060 } // namespace LogCabin::RPC
00061 } // namespace LogCabin
00062 
00063 #endif /* LOGCABIN_RPC_SERVICE_H */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines