A platform for high-performance distributed tool and library development written in C++. It can be deployed in two different cluster modes: standalone or distributed. API for v0.5.0, released on June 13, 2018.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SimpleRequest.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * *
3  * Copyright 2018 Rice University *
4  * *
5  * Licensed under the Apache License, Version 2.0 (the "License"); *
6  * you may not use this file except in compliance with the License. *
7  * You may obtain a copy of the License at *
8  * *
9  * http://www.apache.org/licenses/LICENSE-2.0 *
10  * *
11  * Unless required by applicable law or agreed to in writing, software *
12  * distributed under the License is distributed on an "AS IS" BASIS, *
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
14  * See the License for the specific language governing permissions and *
15  * limitations under the License. *
16  * *
17  *****************************************************************************/
18 
19 #ifndef SIMPLE_REQUEST_H
20 #define SIMPLE_REQUEST_H
21 
22 #include "PDBLogger.h"
23 
24 // This templated function makes it easy to write a simple network client that asks a request,
25 // then gets a result. See, for example, CatalogClient.cc for an example of how to use.
26 //
27 // The type args are:
28 // RequestType: the type of object to create to send over the wire
29 // ResponseType: the type of object we expect to receive over the wire
30 // ReturnType: the type we will return to the caller
31 // RequestTypeParams: type of the params to use for the contructor to the object we send over the
32 //wre
33 //
34 // The params are:
35 // myLogger: The logger we write error messages to
36 // port: the port to send the request to
37 // address: the address to send the request to
38 // onErr: the value to return if there is an error sending/receiving data
39 // bytesForRequest: the number of bytes to give to the allocator used to build the request
40 // processResponse: the function used to process the response to the request
41 // args: the arguments to give to the constructor of the request
42 //
43 
44 namespace pdb {
45 
46 template <class RequestType, class ResponseType, class ReturnType, class... RequestTypeParams>
47 ReturnType simpleRequest(PDBLoggerPtr myLogger,
48  int port,
49  std::string address,
50  ReturnType onErr,
51  size_t bytesForRequest,
52  function<ReturnType(Handle<ResponseType>)> processResponse,
53  RequestTypeParams&&... args);
54 }
55 
56 // This is a similar templated function that sends two objects, in sequence and then asks for the
57 // results.
58 //
59 // The type args are:
60 // RequestType: the type of object to create to send over the wire
61 // SecondRequestType: the second object to create and send over the wirte
62 // ResponseType: the type of object we expect to receive over the wire
63 // ReturnType: the type we will return to the caller
64 // RequestTypeParams: type of the params to use for the contructor to the object we send over the
65 //wre
66 //
67 // The params are:
68 // myLogger: The logger we write error messages to
69 // port: the port to send the request to
70 // address: the address to send the request to
71 // onErr: the value to return if there is an error sending/receiving data
72 // bytesForRequest: the number of bytes to give to the allocator used to build the request
73 // processResponse: the function used to process the response to the request
74 // firstRequest: the first request to send over the wire
75 // secondRequest: the second request to send over the wire
76 
77 namespace pdb {
78 
79 template <class RequestType, class SecondRequestType, class ResponseType, class ReturnType>
80 ReturnType simpleDoubleRequest(PDBLoggerPtr myLogger,
81  int port,
82  std::string address,
83  ReturnType onErr,
84  size_t bytesForRequest,
85  function<ReturnType(Handle<ResponseType>)> processResponse,
86  Handle<RequestType>& firstRequest,
87  Handle<SecondRequestType>& secondRequest);
88 }
89 
90 #endif
91 
92 #include "SimpleRequest.cc"
ReturnType simpleDoubleRequest(PDBLoggerPtr myLogger, int port, std::string address, ReturnType onErr, size_t bytesForRequest, function< ReturnType(Handle< ResponseType >)> processResponse, Handle< RequestType > &firstRequest, Handle< SecondRequestType > &secondRequest)
std::shared_ptr< PDBLogger > PDBLoggerPtr
Definition: PDBLogger.h:40
ReturnType simpleRequest(PDBLoggerPtr myLogger, int port, std::string address, ReturnType onErr, size_t bytesForRequest, function< ReturnType(Handle< ResponseType >)> processResponse, RequestTypeParams &&...args)