blob: 1e69e7e88eefc3e2ad6c78b77a26b63be893ec45 [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
46void freeNames(char** names, size_t len) {
47 for (int i = 0; i < len; i++) {
48 free(names[i]);
49 }
50 delete[] names;
51}