2018-01-29 19:01:17 +08:00
|
|
|
/*
|
|
|
|
* Copyright 2018 The Cartographer Authors
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2018-03-02 21:16:49 +08:00
|
|
|
#ifndef CARTOGRAPHER_GRPC_INTERNAL_FRAMEWORK_TESTING_RPC_HANDLER_WRAPPER_H_
|
|
|
|
#define CARTOGRAPHER_GRPC_INTERNAL_FRAMEWORK_TESTING_RPC_HANDLER_WRAPPER_H_
|
2018-01-29 19:01:17 +08:00
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
|
2018-03-03 06:21:28 +08:00
|
|
|
namespace cartographer {
|
|
|
|
namespace cloud {
|
2018-01-29 19:01:17 +08:00
|
|
|
namespace framework {
|
|
|
|
namespace testing {
|
|
|
|
|
|
|
|
template <class RpcHandlerType>
|
|
|
|
class RpcHandlerWrapper : public RpcHandlerType {
|
|
|
|
public:
|
|
|
|
enum RpcHandlerEvent { ON_REQUEST, ON_READS_DONE, ON_FINISH };
|
|
|
|
using EventCallback = std::function<void(RpcHandlerEvent)>;
|
|
|
|
|
|
|
|
RpcHandlerWrapper(EventCallback event_callback)
|
|
|
|
: event_callback_(event_callback) {}
|
|
|
|
|
|
|
|
void OnRequest(const typename RpcHandlerType::RequestType &request) override {
|
|
|
|
RpcHandlerType::OnRequest(request);
|
|
|
|
event_callback_(ON_REQUEST);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnReadsDone() override {
|
|
|
|
RpcHandlerType::OnReadsDone();
|
|
|
|
event_callback_(ON_READS_DONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnFinish() override {
|
|
|
|
RpcHandlerType::OnFinish();
|
|
|
|
event_callback_(ON_FINISH);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
EventCallback event_callback_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace testing
|
|
|
|
} // namespace framework
|
2018-03-03 06:21:28 +08:00
|
|
|
} // namespace cloud
|
|
|
|
} // namespace cartographer
|
2018-01-29 19:01:17 +08:00
|
|
|
|
2018-03-02 21:16:49 +08:00
|
|
|
#endif // CARTOGRAPHER_GRPC_INTERNAL_FRAMEWORK_TESTING_RPC_HANDLER_WRAPPER_H_
|