Skip to content

Commit

Permalink
frameworks/wasm: Add kvdb missing interface in frameworks
Browse files Browse the repository at this point in the history
add kvdb interface, interface name property_set_buffer
  • Loading branch information
zhuanglinx authored and pengxianghao21 committed Jan 20, 2025
1 parent a16f2da commit 75519c3
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 0 deletions.
26 changes: 26 additions & 0 deletions kvdb/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# ##############################################################################
# apps/frameworks/chre/CMakeLists.txt
#
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with this work for
# additional information regarding copyright ownership. The ASF licenses this
# file to you 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.
#
# ##############################################################################

if(CONFIG_KVDB AND CONFIG_INTERPRETERS_WAMR_EXTERNAL_MODULE_REGISTRY)

target_sources(apps PRIVATE kvdb.c)
# register WAMR mod
nuttx_add_wamrmod(MODS kvdb)
endif()
23 changes: 23 additions & 0 deletions kvdb/Make.defs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
############################################################################
# apps/frameworks/runtimes/wasm/chre/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you 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.
#
############################################################################

ifeq ($(CONFIG_KVDB)$(CONFIG_INTERPRETERS_WAMR_EXTERNAL_MODULE_REGISTRY),yy)
CONFIGURED_APPS += $(APPDIR)/frameworks/runtimes/wasm/kvdb
endif
35 changes: 35 additions & 0 deletions kvdb/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
############################################################################
# apps/frameworks/wasm/chre/Makefile
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you 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 $(APPDIR)/Make.defs

CSRCS += kvdb.c

# To delete the Kconfig file, an empty preconfig needs to be added.
preconfig::

# Set WAMR_MODULE_NAME and include Module.mk to add this module to the list of
# builtin modules for the WAMR runtime. WAMR_MODULE_NAME must be unique across all
# modules in system.

WAMR_MODULE_NAME = kvdb

include $(APPDIR)/interpreters/wamr/Module.mk
include $(APPDIR)/Application.mk
53 changes: 53 additions & 0 deletions kvdb/kvdb.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (C) 2024 Xiaomi Corperation
*
* 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.
*/

/****************************************************************************
* Included Files
****************************************************************************/

#include <stdint.h>
#include <sys/param.h>

#include "kvdb.h"
#include "wasm_export.h"

/****************************************************************************
* Private Functions
****************************************************************************/

static int property_set_buffer_wrapper(wasm_exec_env_t env,
const char* key,
const void* value,
size_t size)
{
return property_set_buffer(key, value, size);
}

static NativeSymbol g_kvdb_symbols[] = {
EXPORT_WASM_API_WITH_SIG2(property_set_buffer, "($*i)i"),
};

/****************************************************************************
* Public Functions
****************************************************************************/

bool wamr_module_kvdb_register(void)
{
/* Add frameworks section init hook here */

return wasm_runtime_register_natives("env", g_kvdb_symbols,
nitems(g_kvdb_symbols));
}

0 comments on commit 75519c3

Please sign in to comment.