blob: dbdc04671947488fc4556ded05d2974b8c243145 [file] [log] [blame]
Joel Galensonc19f0062021-02-22 09:52:18 -08001/*
2 * Copyright (C) 2021 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
17#include "vintf.hpp"
18
19#include <vintf/HalManifest.h>
20#include <vintf/VintfObject.h>
21
22// Converts a set<string> into a C-style array of C strings.
23static char** convert(const std::set<std::string>& names) {
24 char** ret = new char*[names.size()];
25 char** ptr = ret;
26 for (const auto& name : names) {
27 *(ptr++) = strdup(name.c_str());
28 }
29 return ret;
30}
31
32char** getHalNames(size_t* len) {
33 auto manifest = android::vintf::VintfObject::GetDeviceHalManifest();
34 const auto names = manifest->getHalNames();
35 *len = names.size();
36 return convert(names);
37}
38
39char** getHalNamesAndVersions(size_t* len) {
40 auto manifest = android::vintf::VintfObject::GetDeviceHalManifest();
41 const auto names = manifest->getHalNamesAndVersions();
42 *len = names.size();
43 return convert(names);
44}
45
Janis Danisevskisef14e1a2021-02-23 23:16:55 -080046char** getAidlInstances(size_t* len, const char* package, size_t version,
47 const char* interfaceName) {
48 auto manifest = android::vintf::VintfObject::GetDeviceHalManifest();
49 const auto names = manifest->getAidlInstances(package, version, interfaceName);
50 *len = names.size();
51 return convert(names);
52}
53
Joel Galensonc19f0062021-02-22 09:52:18 -080054void freeNames(char** names, size_t len) {
55 for (int i = 0; i < len; i++) {
56 free(names[i]);
57 }
58 delete[] names;
59}