OLD | NEW |
| (Empty) |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "blimp/test/fake_engine/fake_engine.h" | |
6 | |
7 #include <fcntl.h> | |
8 | |
9 #include "base/logging.h" | |
10 #include "blimp/test/fake_engine/proto/engine.grpc.pb.h" | |
11 #include "blimp/test/fake_engine/proto/lifetime.grpc.pb.h" | |
12 #include "blimp/test/fake_engine/proto/logging.grpc.pb.h" | |
13 #include "third_party/grpc/include/grpc++/create_channel_posix.h" | |
14 #include "third_party/grpc/include/grpc++/grpc++.h" | |
15 #include "third_party/grpc/include/grpc++/server_posix.h" | |
16 | |
17 namespace blimp { | |
18 | |
19 grpc::Status EngineServiceImpl::CheckHealth( | |
20 grpc::ServerContext* context, | |
21 const CheckHealthRequest* request, | |
22 CheckHealthResponse* response) { | |
23 response->set_status(CheckHealthResponse::OK); | |
24 return grpc::Status::OK; | |
25 } | |
26 | |
27 grpc::Status EngineServiceImpl::ShutDown( | |
28 grpc::ServerContext* context, | |
29 const ShutDownRequest* request, | |
30 ShutDownResponse* response) { | |
31 exit(0); | |
32 return grpc::Status::OK; | |
33 } | |
34 | |
35 FakeEngine::FakeEngine() = default; | |
36 FakeEngine::~FakeEngine() = default; | |
37 | |
38 void FakeEngine::Start() { | |
39 DCHECK(!grpc_server_) << "FakeEngine already started."; | |
40 | |
41 grpc::ServerBuilder builder; | |
42 builder.RegisterService(&engine_service_); | |
43 grpc_server_ = builder.BuildAndStart(); | |
44 | |
45 // TODO(xyzzyz): Remove fcntl when https://github.com/grpc/grpc/pull/8051 is | |
46 // merged and added to Chromium. | |
47 int flags = fcntl(kEngineListenFd, F_GETFL, 0); | |
48 CHECK_EQ(0, fcntl(kEngineListenFd, F_SETFL, flags | O_NONBLOCK)); | |
49 | |
50 grpc::AddInsecureChannelFromFd(grpc_server_.get(), kEngineListenFd); | |
51 VLOG(1) << "Started engine server."; | |
52 | |
53 rendering_server_channel_ = grpc::CreateInsecureChannelFromFd( | |
54 "rendering_server", kRenderingServerListenFd); | |
55 lifetime_stub_ = Lifetime::NewStub(rendering_server_channel_); | |
56 logging_stub_ = Logging::NewStub(rendering_server_channel_); | |
57 | |
58 EngineReadyRequest request; | |
59 EngineReadyResponse response; | |
60 | |
61 grpc::ClientContext context; | |
62 grpc::Status status = lifetime_stub_->EngineReady( | |
63 &context, request, &response); | |
64 | |
65 CHECK(status.ok()) << "EngineReady RPC failed: " | |
66 << status.error_code() << ": " << status.error_message(); | |
67 VLOG(1) << "EngineReady RPC success"; | |
68 } | |
69 | |
70 void FakeEngine::WaitForShutdown() { | |
71 DCHECK(grpc_server_) << "FakeEngine not started."; | |
72 grpc_server_->Wait(); | |
73 } | |
74 | |
75 Lifetime::Stub* FakeEngine::GetLifetimeStub() { | |
76 return lifetime_stub_.get(); | |
77 } | |
78 | |
79 Logging::Stub* FakeEngine::GetLoggingStub() { | |
80 return logging_stub_.get(); | |
81 } | |
82 | |
83 } // namespace blimp | |
OLD | NEW |