2 * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
25 #include <halcc/hal-compatibility-checker.h>
26 #include <hal-common.h>
28 #include "halcc-object.h"
29 #include "halcc-parser.h"
30 #include "halcc-util.h"
32 struct callback_data {
33 halcc_compatibility_cb func;
37 static int parse_directory(const char *manifest_dir, halcc_manifest *manifest)
43 if (!manifest_dir || !manifest)
46 dir = opendir(manifest_dir);
48 printf("Failed to opendir '%s', %m\n", manifest_dir);
54 while ((entry = readdir(dir))) {
58 if (entry->d_type != DT_REG)
61 fd = openat(dfd, entry->d_name, O_RDONLY);
63 printf("Failed to openat(), %m\n");
67 ret = halcc_parse_fd(fd, manifest);
69 printf("Failed to parse xml, ret=%d\n", ret);
82 static halcc_compatibility_e is_compatible(int major, int minor, unsigned int abi_version)
84 if (abi_version == HAL_ABI_VERSION_UNKNOWN)
85 return HALCC_INCOMPATIBLE;
87 return HALCC_COMPATIBLE;
90 static void foreach_hal(void *data, void *user_data)
92 struct callback_data *callback_data = NULL;
93 enum hal_module module;
95 const char *hal_name = NULL;
97 halcc_compatibility_e compatible = HALCC_INCOMPATIBLE;
99 hal = (halcc_hal *) data;
100 callback_data = (struct callback_data *) user_data;
103 assert(callback_data);
104 assert(callback_data->func);
106 if (halcc_hal_get_name(hal, &hal_name) < 0 || hal_name == NULL)
109 if (halcc_hal_get_version(hal, &major, &minor, NULL) < 0)
112 for (module = HAL_MODULE_UNKNOWN; module < HAL_MODULE_END; ++module) {
113 char module_name[128] = { 0 , };
114 unsigned int abi_version;
117 ret = hal_common_get_backend_module_name(module, module_name, sizeof(module_name));
121 ret = strncmp(hal_name, module_name, strlen(hal_name) + 1);
125 abi_version = hal_common_get_backend_abi_version(module);
126 if (abi_version == HAL_ABI_VERSION_UNKNOWN)
129 compatible = is_compatible(major, minor, abi_version);
133 if (module >= HAL_MODULE_END) {
134 printf("Unknown hal module: %s\n", hal_name);
138 printf("%s: %s\n", hal_name, compatible ? "Compatible" : "Incompatible");
140 callback_data->func(module, compatible, callback_data->user_data);
144 int halcc_check_compatibility(const char *hal_api_manifest_dir,
145 halcc_compatibility_cb callback, void *user_data)
147 halcc_manifest *manifest = NULL;
148 struct callback_data callback_data = { 0 , };
151 if (!hal_api_manifest_dir)
157 ret = halcc_manifest_new(&manifest);
161 ret = parse_directory(hal_api_manifest_dir, manifest);
165 callback_data = (struct callback_data) { callback, user_data };
167 halcc_manifest_foreach_hal(manifest, foreach_hal, &callback_data);
171 halcc_manifest_free(g_steal_pointer(&manifest));