-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathserver.cpp
More file actions
73 lines (55 loc) · 1.69 KB
/
Copy pathserver.cpp
File metadata and controls
73 lines (55 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// SPDX-License-Identifier: AGPL-3.0-or-later
// Copyright (C) 2020 Egor Pugin <egor.pugin@gmail.com>
#include "server.h"
#include <sw/builder/command.h>
#include <grpcpp/grpcpp.h>
#include <primitives/exceptions.h>
#include <primitives/log.h>
DECLARE_STATIC_LOGGER(logger, "builder.distributed.server");
// move this just into builder itself?
namespace sw::builder::distributed
{
DEFINE_SERVICE_METHOD(DistributedBuildService, ExecuteCommand, ::sw::api::build::Command, ::sw::api::build::CommandResult)
{
// fan mode: send to workers in round robin mode
Command c;
c.in.file = fs::u8path(request->in().file());
c.in.file = fs::u8path(request->in().file());
c.in.file = fs::u8path(request->in().file());
c.execute();
GRPC_RETURN_OK();
}
Server::Server()
{
}
Server::~Server()
{
}
void Server::start(const String &server_address/*, const String &cert*/)
{
grpc::SslServerCredentialsOptions ssl_options;
//if (!cert.empty())
//ssl_options.pem_key_cert_pairs.push_back({ read_file("server.key"), read_file("server.crt") });
grpc::ServerBuilder builder;
//if (sw::settings().grpc_use_ssl)
//builder.AddListeningPort(server_address, grpc::SslServerCredentials(ssl_options));
//else
builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
builder.RegisterService(&dbs);
server = builder.BuildAndStart();
if (!server)
throw SW_RUNTIME_ERROR("Cannot start grpc server");
}
void Server::wait()
{
if (!server)
throw SW_RUNTIME_ERROR("Server not started");
server->Wait();
}
void Server::stop()
{
if (!server)
throw SW_RUNTIME_ERROR("Server not started");
server->Shutdown();
}
}