--- /dev/null
+/*
+ * Copyright (c) 2025 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef AURUM_C_BINDINGS_H
+#define AURUM_C_BINDINGS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ // Initialize the Aurum library.
+ void aurum_init();
+ // Dump current screen as JSON string.
+ const char* dump_screen();
+ // Free the allocated string memory.
+ void free_string_result(const char* ptr);
+#ifdef __cplusplus
+}
+#endif
+
+#endif // AURUM_C_BINDINGS_H
\ No newline at end of file
install_headers(libaurum_install_inc,
)
+
+if get_option('build_c_bindings') == true
+ c_bindings_dir = dir_include + '/c_bindings'
+ message('install c bindings header to ' + c_bindings_dir)
+ install_headers('./inc/AurumCBindings.h', install_dir: c_bindings_dir,)
+endif
--- /dev/null
+/*
+ * Copyright (c) 2025 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "AurumCBindings.h"
+#include "Aurum.h"
+#include <cstring>
+
+using namespace Aurum;
+
+namespace
+{
+ constexpr const char WINDOWS_KEY[] = "\"windows\"";
+}
+
+void aurum_init()
+{
+ LOGI("aurum_init");
+ AccessibleWatcher::getInstance();
+}
+
+const char* dump_screen()
+{
+ LOGI("dump_screen");
+ auto device = UiDevice::getInstance();
+ auto windowRoots = device->getWindowRoot();
+ std::string dumpResult{WINDOWS_KEY};
+ dumpResult += " : [";
+
+ for (const auto& root: windowRoots) {
+ // TODO: implement dump logic
+ // root->dump();
+ dumpResult += "{},";
+ }
+
+ // remove last comma if exists.
+ if(dumpResult.back() == ',') {
+ dumpResult.pop_back();
+ }
+
+ dumpResult += "]";
+ char* cResult = new char[dumpResult.size() + 1]; // Consumers must free this memory later
+ std::strcpy(cResult, dumpResult.c_str());
+ return cResult;
+
+}
+
+void free_string_result(const char* ptr)
+{
+ LOGI("free_string_result");
+ delete[] ptr;
+}
\ No newline at end of file
--- /dev/null
+libaurum_src += [
+ files('AurumCBindings.cc'),
+]
subdir('Accessibility')
subdir('Impl')
subdir('Runnable')
+
+if get_option('build_c_bindings') == true
+ subdir('c_bindings')
+endif
value: false,
description: 'skip building grpc and protobuf protocol'
)
+
+option('build_c_bindings',
+ type: 'boolean',
+ value: false,
+ description: 'build c bindings to be called from rust code'
+)
\ No newline at end of file
--- /dev/null
+#include <gtest/gtest.h>
+
+#include <AurumCBindings.h>
+
+TEST(CBindingsTest, DumpScreen)
+{
+ aurum_init();
+ const char *c_str = dump_screen();
+ EXPECT_NE(c_str, nullptr);
+ free_string_result(c_str);
+}
+
+TEST(CBindingsTest, FreeStringResultWorksWithNull)
+{
+ free_string_result(nullptr);
+}
\ No newline at end of file
['test_uiselector', files('Test_UiSelector.cc')],
]
+if get_option('build_c_bindings') == true
+ test_src += [['Test_CBindings', files('Test_CBindings.cc')]]
+endif
+
test_inc = [
include_directories('./')
]