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 "PipeRegistration.h"
17 
18 namespace android {
19 namespace automotive {
20 namespace computepipe {
21 namespace router {
22 namespace V1_0 {
23 namespace implementation {
24 
25 using namespace android::automotive::computepipe;
26 using namespace aidl::android::automotive::computepipe::runner;
27 using namespace ndk;
28 // Methods from ::android::automotive::computepipe::registry::V1_0::IPipeRegistration follow.
registerPipeRunner(const std::string & graphName,const std::shared_ptr<IPipeRunner> & graphRunner)29 ScopedAStatus PipeRegistration::registerPipeRunner(const std::string& graphName,
30                                                    const std::shared_ptr<IPipeRunner>& graphRunner) {
31     if (!mRegistry) {
32         return ScopedAStatus(AStatus_fromExceptionCode(EX_ILLEGAL_STATE));
33     }
34     std::unique_ptr<PipeHandle<PipeRunner>> handle = std::make_unique<RunnerHandle>(graphRunner);
35     auto err = mRegistry->RegisterPipe(std::move(handle), graphName);
36     return convertToBinderStatus(err);
37 }
38 
convertToBinderStatus(Error err)39 ScopedAStatus PipeRegistration::convertToBinderStatus(Error err) {
40     switch (err) {
41         case OK:
42             return ScopedAStatus::ok();
43         default:
44             return ScopedAStatus(AStatus_fromExceptionCode(EX_ILLEGAL_STATE));
45     }
46 }
47 
getIfaceName()48 const char* PipeRegistration::getIfaceName() {
49     return this->descriptor;
50 }
51 }  // namespace implementation
52 }  // namespace V1_0
53 }  // namespace router
54 }  // namespace computepipe
55 }  // namespace automotive
56 }  // namespace android
57