summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarius Vlad <marius.vlad@collabora.com>2022-12-13 20:18:33 +0200
committerMarius Vlad <marius.vlad@collabora.com>2022-12-13 20:19:06 +0200
commitf5aea684ce51fc1c3df13de14bb017ea2b73d39d (patch)
treea8441309b10972400a42bf95f4305774e8a4645e
parent4ccd64899f0219eb8940382467ca88da44f27a1d (diff)
main: Add support for GetOuputs requestsandbox/mvlad/use-grpc-for-activation
Bug-AGL: SPEC-4503 Signed-off-by: Marius Vlad <marius.vlad@collabora.com> Change-Id: I484f2170d62f93c3f01b4131436daf5c144c45e8
-rw-r--r--src/AglShellGrpcClient.cpp21
-rw-r--r--src/AglShellGrpcClient.h1
-rw-r--r--src/agl_shell.proto12
-rw-r--r--src/main.cpp25
4 files changed, 58 insertions, 1 deletions
diff --git a/src/AglShellGrpcClient.cpp b/src/AglShellGrpcClient.cpp
index 0840d28..7f1ce20 100644
--- a/src/AglShellGrpcClient.cpp
+++ b/src/AglShellGrpcClient.cpp
@@ -70,3 +70,24 @@ GrpcClient::AppStatusState(Callback callback)
{
reader->AppStatusState(callback);
}
+
+std::vector<std::string>
+GrpcClient::GetOutputs()
+{
+ grpc::ClientContext context;
+ std::vector<std::string> v;
+
+ ::agl_shell_ipc::OutputRequest request;
+ ::agl_shell_ipc::ListOutputResponse response;
+
+ grpc::Status status = m_stub->GetOutputs(&context, request, &response);
+ if (!status.ok())
+ return std::vector<std::string>();
+
+ for (int i = 0; i < response.outputs_size(); i++) {
+ ::agl_shell_ipc::OutputResponse rresponse = response.outputs(i);
+ v.push_back(rresponse.name());
+ }
+
+ return v;
+}
diff --git a/src/AglShellGrpcClient.h b/src/AglShellGrpcClient.h
index 50531f9..aedde07 100644
--- a/src/AglShellGrpcClient.h
+++ b/src/AglShellGrpcClient.h
@@ -92,6 +92,7 @@ public:
GrpcClient();
bool ActivateApp(const std::string& app_id, const std::string& output_name);
bool DeactivateApp(const std::string& app_id);
+ std::vector<std::string> GetOutputs();
void GetAppState();
void AppStatusState(Callback callback);
grpc::Status Wait();
diff --git a/src/agl_shell.proto b/src/agl_shell.proto
index 9cf238a..22fad1c 100644
--- a/src/agl_shell.proto
+++ b/src/agl_shell.proto
@@ -9,6 +9,7 @@ service AglShellManagerService {
rpc SetAppSplit(SplitRequest) returns (SplitResponse) {}
rpc SetAppFloat(FloatRequest) returns (FloatResponse) {}
rpc AppStatusState(AppStateRequest) returns (stream AppStateResponse) {}
+ rpc GetOutputs(OutputRequest) returns (ListOutputResponse) {}
}
message ActivateRequest {
@@ -48,3 +49,14 @@ message AppStateResponse {
int32 state = 1;
string app_id = 2;
}
+
+message OutputRequest {
+};
+
+message OutputResponse {
+ string name = 1;
+};
+
+message ListOutputResponse {
+ repeated OutputResponse outputs = 1;
+};
diff --git a/src/main.cpp b/src/main.cpp
index 7ebde3b..24f3288 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -46,6 +46,7 @@ enum action_state {
DEACTIVATE,
SET_FLOAT,
SET_SPLIT,
+ GETOUTPUTS,
};
static struct action {
@@ -54,6 +55,7 @@ static struct action {
} actions[] = {
{ ACTIVATE, "ACTIVATE" },
{ DEACTIVATE, "DEACTIVATE" },
+ { GETOUTPUTS, "GETOUTPUTS" },
};
static int
@@ -80,6 +82,10 @@ help(char **argv)
{
fprintf(stderr, "Usage: %s [-a action] [-p app_id] [-o output_name] [-l]\n",
argv[0]);
+ fprintf(stderr, "\t-a -- action activate|deactivate|getoutputs\n");
+ fprintf(stderr, "\t-p -- app_id application_id\n");
+ fprintf(stderr, "\t-o -- output_name one of the outputs from getoutputs action\n");
+ fprintf(stderr, "\t-l -- continuously listen for window state events\n");
exit(EXIT_FAILURE);
}
@@ -91,6 +97,20 @@ app_status_callback(::agl_shell_ipc::AppStateResponse app_response)
app_response.state() << std::endl;
}
+static void
+read_outputs(GrpcClient *client)
+{
+ std::vector<std::string> outputs = client->GetOutputs();
+
+ if (outputs.empty())
+ return;
+
+ for (size_t i = 0; i < outputs.size(); i++)
+ fprintf(stderr, " %s ", outputs[i].c_str());
+
+ fprintf(stderr, "\n");
+}
+
int main(int argc, char *argv[])
{
char *output = NULL;
@@ -101,7 +121,7 @@ int main(int argc, char *argv[])
std::thread th;
// app_id, output p[0] -> name, p[1] action, p[2] app_id, p[3] -> output
- while ((opt = getopt(argc, argv, "a:p:o:lh")) != -1) {
+ while ((opt = getopt(argc, argv, "a:p:o:lsh")) != -1) {
switch (opt) {
case 'p':
app_id = optarg;
@@ -153,6 +173,9 @@ int main(int argc, char *argv[])
fprintf(stderr, "Deactivating application '%s'\n", app_id);
client->DeactivateApp(std::string(app_id));
break;
+ case GETOUTPUTS:
+ read_outputs(client);
+ break;
default:
// allow listen flag to be passed
if (listen_flag)