Skip to content

Commit c74fdba

Browse files
author
Michel Vocks
committed
small improvements
1 parent 0a9c7dd commit c74fdba

File tree

3 files changed

+60
-58
lines changed

3 files changed

+60
-58
lines changed

Diff for: Makefile

+3-5
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ PROTOS_PATH = ./
3636

3737
vpath %.proto $(PROTOS_PATH)
3838

39-
all: system-check run
39+
all: system-check compile
4040

4141
%.grpc.pb.cc: %.proto
4242
$(PROTOC) -I $(PROTOS_PATH) --grpc_out=. --plugin=protoc-gen-grpc=$(GRPC_CPP_PLUGIN_PATH) $<
@@ -47,10 +47,8 @@ all: system-check run
4747
clean:
4848
rm -f *.out *.pb.cc *.pb.h
4949

50-
run:
51-
$(CXX) sdk.cc plugin.grpc.pb.cc plugin.pb.cc $(LDFLAGS) $(CXXFLAGS) -o sdk.out
52-
./sdk.out
53-
50+
compile:
51+
$(CXX) -c sdk.cc plugin.grpc.pb.cc plugin.pb.cc $(LDFLAGS) $(CXXFLAGS)
5452

5553
# The following is to test your system and ensure a smoother experience.
5654
# They are by no means necessary to actually compile a grpc-enabled software.

Diff for: sdk.cc

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#include <string>
2+
#include <iostream>
23
#include <memory>
34
#include <algorithm>
45
#include <cstdlib>
56
#include <fstream>
6-
#include <fstream>
77
#include <sstream>
88
#include <grpcpp/grpcpp.h>
99
#include <grpcpp/health_check_service_interface.h>
@@ -54,15 +54,15 @@ class GRPCPluginImpl final : public Plugin::Service {
5454
}
5555

5656
Status ExecuteJob(ServerContext* context, const Job* request, JobResult* response) {
57-
job_wrapper * job = GetJob((*request));
57+
gaia::job_wrapper * job = GetJob((*request));
5858
if (job == nullptr) {
5959
return Status(grpc::StatusCode::CANCELLED, ERR_JOB_NOT_FOUND);
6060
}
6161

6262
// Transform arguments.
63-
list<argument> args;
63+
list<gaia::argument> args;
6464
for (int i = 0; i < (*request).args_size(); ++i) {
65-
argument arg = {};
65+
gaia::argument arg = {};
6666
arg.key = (*request).args(i).key();
6767
arg.value = (*request).args(i).value();
6868
args.push_back(arg);
@@ -87,11 +87,11 @@ class GRPCPluginImpl final : public Plugin::Service {
8787
return Status::OK;
8888
}
8989

90-
void PushCachedJobs(job_wrapper* job) {
90+
void PushCachedJobs(gaia::job_wrapper* job) {
9191
cached_jobs.push_back(*job);
9292
}
9393

94-
static bool compare(job_wrapper a, job_wrapper b) {
94+
static bool compare(gaia::job_wrapper a, gaia::job_wrapper b) {
9595
return (a.job.unique_id() == b.job.unique_id());
9696
}
9797

@@ -104,10 +104,10 @@ class GRPCPluginImpl final : public Plugin::Service {
104104
}
105105

106106
private:
107-
list<job_wrapper> cached_jobs;
107+
list<gaia::job_wrapper> cached_jobs;
108108

109109
// GetJob finds the right job in the cache and returns it.
110-
job_wrapper * GetJob(const Job job) {
110+
gaia::job_wrapper * GetJob(const Job job) {
111111
for (auto & cached_job : cached_jobs) {
112112
if (cached_job.job.unique_id() == job.unique_id()) {
113113
return &cached_job;
@@ -139,7 +139,7 @@ static bool read_file(const string& filename, string& data) {
139139
return false;
140140
}
141141

142-
static void Serve(list<job> jobs) throw(string) {
142+
void Serve(list<gaia::job> jobs) throw(string) {
143143
// Allocate space for objects.
144144
GRPCPluginImpl service;
145145
ServerBuilder builder;
@@ -195,7 +195,7 @@ static void Serve(list<job> jobs) throw(string) {
195195
}
196196

197197
// Create the jobs wrapper object.
198-
job_wrapper w = {
198+
gaia::job_wrapper w = {
199199
job.handler,
200200
(*proto_job),
201201
};

Diff for: sdk.h

+47-43
Original file line numberDiff line numberDiff line change
@@ -10,51 +10,55 @@ using std::string;
1010
using std::list;
1111
using proto::Job;
1212

13-
struct InputType {
14-
enum class input_type {
15-
textfield,
16-
textarea,
17-
boolean,
18-
vault
13+
namespace gaia {
14+
struct InputType {
15+
enum class input_type {
16+
textfield,
17+
textarea,
18+
boolean,
19+
vault
20+
};
1921
};
20-
};
21-
22-
const string ToString (InputType::input_type es) {
23-
const std::map<InputType::input_type,const string> EnumStrings {
24-
{ InputType::input_type::textfield, "textfield" },
25-
{ InputType::input_type::textarea, "textarea" },
26-
{ InputType::input_type::boolean, "boolean" },
27-
{ InputType::input_type::vault, "vault" }
22+
23+
const string ToString (InputType::input_type es) {
24+
const std::map<InputType::input_type,const string> EnumStrings {
25+
{ InputType::input_type::textfield, "textfield" },
26+
{ InputType::input_type::textarea, "textarea" },
27+
{ InputType::input_type::boolean, "boolean" },
28+
{ InputType::input_type::vault, "vault" }
29+
};
30+
auto it = EnumStrings.find(es);
31+
return it == EnumStrings.end() ? "Out of range" : it->second;
32+
}
33+
34+
struct argument {
35+
string description;
36+
InputType::input_type type;
37+
string key;
38+
string value;
39+
};
40+
41+
struct manual_interaction {
42+
string description;
43+
InputType::input_type type;
44+
string value;
2845
};
29-
auto it = EnumStrings.find(es);
30-
return it == EnumStrings.end() ? "Out of range" : it->second;
31-
}
3246

33-
struct argument {
34-
string description;
35-
InputType::input_type type;
36-
string key;
37-
string value;
38-
};
39-
40-
struct manual_interaction {
41-
string description;
42-
InputType::input_type type;
43-
string value;
44-
};
45-
46-
struct job {
47-
void (*handler)(list<argument>) throw(string);
48-
string title;
49-
string description;
50-
list<string> depends_on;
51-
list<argument> args;
52-
manual_interaction * interaction;
53-
};
54-
55-
struct job_wrapper {
56-
void (*handler)(list<argument>) throw(string);
57-
Job job;
58-
};
47+
struct job {
48+
void (*handler)(list<argument>) throw(string);
49+
string title;
50+
string description;
51+
list<string> depends_on;
52+
list<argument> args;
53+
manual_interaction * interaction;
54+
};
55+
56+
struct job_wrapper {
57+
void (*handler)(list<argument>) throw(string);
58+
Job job;
59+
};
60+
61+
void Serve(list<job>) throw(string);
62+
}
5963

6064
#endif

0 commit comments

Comments
 (0)