1 /**
2  * Copyright 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #include "PipeQuery.h"
17 
18 #include "PipeClient.h"
19 
20 namespace android {
21 namespace automotive {
22 namespace computepipe {
23 namespace router {
24 namespace V1_0 {
25 namespace implementation {
26 
27 using namespace android::automotive::computepipe::router;
28 using namespace aidl::android::automotive::computepipe::registry;
29 using namespace aidl::android::automotive::computepipe::runner;
30 using namespace ndk;
31 
getGraphList(std::vector<std::string> * outNames)32 ScopedAStatus PipeQuery::getGraphList(std::vector<std::string>* outNames) {
33     if (!mRegistry || !outNames) {
34         return ScopedAStatus(AStatus_fromExceptionCode(EX_ILLEGAL_STATE));
35     }
36     auto names = mRegistry->getPipeList();
37     std::copy(names.begin(), names.end(), std::back_inserter(*outNames));
38     return ScopedAStatus::ok();
39 }
40 
getPipeRunner(const std::string & graphName,const std::shared_ptr<IClientInfo> & info,std::shared_ptr<IPipeRunner> * outRunner)41 ScopedAStatus PipeQuery::getPipeRunner(const std::string& graphName,
42                                        const std::shared_ptr<IClientInfo>& info,
43                                        std::shared_ptr<IPipeRunner>* outRunner) {
44     *outRunner = nullptr;
45     if (!mRegistry) {
46         return ScopedAStatus(AStatus_fromExceptionCode(EX_ILLEGAL_STATE));
47     }
48     std::unique_ptr<ClientHandle> clientHandle = std::make_unique<PipeClient>(info);
49     auto pipeHandle = mRegistry->getClientPipeHandle(graphName, std::move(clientHandle));
50     if (!pipeHandle) {
51         return ScopedAStatus(AStatus_fromExceptionCode(EX_ILLEGAL_STATE));
52     }
53     auto pipeRunner = pipeHandle->getInterface();
54     *outRunner = pipeRunner->runner;
55     return ScopedAStatus::ok();
56 }
57 
getIfaceName()58 const char* PipeQuery::getIfaceName() {
59     return this->descriptor;
60 }
61 }  // namespace implementation
62 }  // namespace V1_0
63 }  // namespace router
64 }  // namespace computepipe
65 }  // namespace automotive
66 }  // namespace android
67