1 // Copyright 2020 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 #include <android-base/logging.h>
15 #include <android/binder_process.h>
16 #include <utils/Errors.h>
17 #include <utils/Log.h>
18
19 #include <iostream>
20 #include <memory>
21 #include <thread>
22
23 #include "ClientConfig.pb.h"
24 #include "ClientInterface.h"
25 #include "MemHandle.h"
26 #include "Options.pb.h"
27 #include "PrebuiltGraph.h"
28 #include "RunnerEngine.h"
29 #include "types/Status.h"
30
31 using android::automotive::computepipe::Status;
32 using android::automotive::computepipe::graph::PrebuiltGraph;
33 using android::automotive::computepipe::proto::ClientConfig;
34 using android::automotive::computepipe::proto::Options;
35 using android::automotive::computepipe::runner::client_interface::ClientInterface;
36 using android::automotive::computepipe::runner::client_interface::ClientInterfaceFactory;
37 using android::automotive::computepipe::runner::engine::RunnerEngine;
38 using android::automotive::computepipe::runner::engine::RunnerEngineFactory;
39
40 namespace {
41 RunnerEngineFactory sEngineFactory;
42 ClientInterfaceFactory sClientFactory;
43 } // namespace
terminate(bool isError,std::string msg)44 void terminate(bool isError, std::string msg) {
45 if (isError) {
46 LOG(ERROR) << "Error msg " << msg;
47 exit(2);
48 }
49 LOG(ERROR) << "Test complete";
50 exit(0);
51 }
52
main(int,char **)53 int main(int /* argc */, char** /* argv */) {
54 std::shared_ptr<RunnerEngine> engine =
55 sEngineFactory.createRunnerEngine(RunnerEngineFactory::kDefault, "");
56
57 std::unique_ptr<PrebuiltGraph> graph;
58 graph.reset(android::automotive::computepipe::graph::GetLocalGraphFromLibrary("libfacegraph.so",
59 engine));
60
61 Options options = graph->GetSupportedGraphConfigs();
62 engine->setPrebuiltGraph(std::move(graph));
63
64 std::function<void(bool, std::string)> cb = terminate;
65 std::unique_ptr<ClientInterface> client =
66 sClientFactory.createClientInterface("aidl", options, engine);
67 if (!client) {
68 std::cerr << "Unable to allocate client";
69 return -1;
70 }
71 engine->setClientInterface(std::move(client));
72 ABinderProcess_startThreadPool();
73 engine->activate();
74 ABinderProcess_joinThreadPool();
75 return 0;
76 }
77