From d919f9af9bc635237e685786ce0c391a3bbb6e3d Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Mon, 6 Feb 2017 16:50:21 +0900 Subject: [PATCH 01/16] Add the code skeleton of store service & client Change-Id: Idba58d12d22df60823f93ec11183a4ad04a98a18 Signed-off-by: Mu-Woong Lee --- .gitignore | 1 + AUTHORS | 3 + CMakeLists.txt | 32 +++++ LICENSE | 204 +++++++++++++++++++++++++++++++ context-store.pc.in | 13 ++ include/ContextStoreService.h | 39 ++++++ include/ContextStoreTypes.h | 23 ++++ include/TestAPI.h | 33 +++++ packaging/context-store.manifest | 5 + packaging/context-store.spec | 97 +++++++++++++++ src/client-dummy/CMakeLists.txt | 34 ++++++ src/client-dummy/TestAPI.cpp | 26 ++++ src/client/CMakeLists.txt | 19 +++ src/client/TestAPI.cpp | 36 ++++++ src/server-dummy/CMakeLists.txt | 34 ++++++ src/server-dummy/ContextStoreService.cpp | 39 ++++++ src/server/CMakeLists.txt | 19 +++ src/server/ContextStoreClientProxy.cpp | 45 +++++++ src/server/ContextStoreClientProxy.h | 35 ++++++ src/server/ContextStoreService.cpp | 40 ++++++ src/shared/ContextStoreTypesPrivate.h | 29 +++++ 21 files changed, 806 insertions(+) create mode 100644 .gitignore create mode 100644 AUTHORS create mode 100644 CMakeLists.txt create mode 100644 LICENSE create mode 100644 context-store.pc.in create mode 100644 include/ContextStoreService.h create mode 100644 include/ContextStoreTypes.h create mode 100644 include/TestAPI.h create mode 100644 packaging/context-store.manifest create mode 100644 packaging/context-store.spec create mode 100644 src/client-dummy/CMakeLists.txt create mode 100644 src/client-dummy/TestAPI.cpp create mode 100644 src/client/CMakeLists.txt create mode 100644 src/client/TestAPI.cpp create mode 100644 src/server-dummy/CMakeLists.txt create mode 100644 src/server-dummy/ContextStoreService.cpp create mode 100644 src/server/CMakeLists.txt create mode 100644 src/server/ContextStoreClientProxy.cpp create mode 100644 src/server/ContextStoreClientProxy.h create mode 100644 src/server/ContextStoreService.cpp create mode 100644 src/shared/ContextStoreTypesPrivate.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a01ee28 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.*.swp diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..44b24d6 --- /dev/null +++ b/AUTHORS @@ -0,0 +1,3 @@ +Mu-Woong Lee +Somin Kim +Kibak Yoon diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..4d15b53 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,32 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(context-store) +INCLUDE(GNUInstallDirs) + +SET(DEPS "glib-2.0 gio-2.0 dlog capi-base-common") +SET(INCDIR "context-service") + +INCLUDE_DIRECTORIES( + ${CMAKE_SOURCE_DIR}/include + ${CMAKE_SOURCE_DIR}/src/shared +) + +ADD_DEFINITIONS(-O2 -Wall -fPIC -fdata-sections -ffunction-sections -fvisibility=hidden) +ADD_DEFINITIONS(-DLOG_TAG="CONTEXT-STORE") +SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fPIC -Wl,--as-needed -Wl,--gc-section -Wl,--print-gc-section") + +SET(VERSION ${FULLVER}) +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +SET(PC_INCLUDE "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/${INCDIR}") +SET(PC_LIBDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") +SET(PC_CFLAGS -I\${includedir}/${INCDIR}) + +INSTALL( + DIRECTORY ${CMAKE_SOURCE_DIR}/include/ + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${INCDIR} + FILES_MATCHING PATTERN "*.h" +) + +ADD_SUBDIRECTORY(src/client-dummy) +ADD_SUBDIRECTORY(src/server-dummy) +ADD_SUBDIRECTORY(src/client) +ADD_SUBDIRECTORY(src/server) diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3ef9807 --- /dev/null +++ b/LICENSE @@ -0,0 +1,204 @@ +Copyright (c) 2017 - 2017 Samsung Electronics Co., Ltd. All rights reserved. + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. + diff --git a/context-store.pc.in b/context-store.pc.in new file mode 100644 index 0000000..378b991 --- /dev/null +++ b/context-store.pc.in @@ -0,0 +1,13 @@ +#Package Information for pkg-config + +prefix=@PREFIX@ +exec_prefix=@PREFIX@ +libdir=@PC_LIBDIR@ +includedir=@PC_INCLUDE@ + +Name: @PC_NAME@ +Description: @PC_DESCRIPTION@ +Version: @VERSION@ +Requires: @PC_REQUIRED@ +Libs: -L${libdir} @PC_LDFLAGS@ +Cflags: -I${includedir} diff --git a/include/ContextStoreService.h b/include/ContextStoreService.h new file mode 100644 index 0000000..209c1f2 --- /dev/null +++ b/include/ContextStoreService.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * 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 __CONTEXT_STORE_SERVICE_H__ +#define __CONTEXT_STORE_SERVICE_H__ + +/* This header SHOULD NOT be included by other headers in this directory. */ + +#include +#include + +namespace ctx { + + class EXPORT_API ContextStoreService : public DBusService { + public: + ContextStoreService(GDBusConnection* conn); + ~ContextStoreService(); + + protected: + void prepare(); + ClientProxy* createProxy(const std::string& busName); + }; + +} + +#endif diff --git a/include/ContextStoreTypes.h b/include/ContextStoreTypes.h new file mode 100644 index 0000000..03bd8b5 --- /dev/null +++ b/include/ContextStoreTypes.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * 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 __CONTEXT_STORE_TYPES_H__ +#define __CONTEXT_STORE_TYPES_H__ + +#include + + +#endif diff --git a/include/TestAPI.h b/include/TestAPI.h new file mode 100644 index 0000000..66b9257 --- /dev/null +++ b/include/TestAPI.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * 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 __CONTEXT_STORE_TEST_API_H__ +#define __CONTEXT_STORE_TEST_API_H__ + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +int context_store_test(); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/packaging/context-store.manifest b/packaging/context-store.manifest new file mode 100644 index 0000000..97e8c31 --- /dev/null +++ b/packaging/context-store.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/packaging/context-store.spec b/packaging/context-store.spec new file mode 100644 index 0000000..5cb13b7 --- /dev/null +++ b/packaging/context-store.spec @@ -0,0 +1,97 @@ +Name: context-store +Summary: Tizen Context Store +Version: 0.0.1 +Release: 1 +Group: Service Framework/Context +License: Apache-2.0 +Source0: %{name}-%{version}.tar.gz + +BuildRequires: cmake +BuildRequires: pkgconfig(glib-2.0) +BuildRequires: pkgconfig(gio-2.0) +BuildRequires: pkgconfig(sqlite3) +BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(capi-base-common) +BuildRequires: pkgconfig(libtzplatform-config) +BuildRequires: pkgconfig(context-common-server) +BuildRequires: pkgconfig(context-common-client) +Provides: %{name}-profile_tv = %{version}-%{release} +Provides: %{name}-profile_ivi = %{version}-%{release} +Provides: %{name}-profile_common = %{version}-%{release} + +%description +Tizen Context Store Service + + +%package genuine +Summary: Genuine Context Store service server and client libraries +Requires: %{name} = %{version}-%{release} +Requires: context-service +Provides: %{name}-profile_mobile = %{version}-%{release} +Provides: %{name}-profile_wearable = %{version}-%{release} + +%description genuine +Binary replacement for context-store. +This genuine context-store package contains actually working shared objects +of the both server and client sides of the context-store service. + + +%package devel +Summary: Tizen Context Store Service API +Group: Service Framework/Context +Requires: %{name} = %{version}-%{release} + +%description devel +Tizen Context Store Service API + + +%prep +%setup -q + +%build +MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` + +export CXXFLAGS+=" -Wextra -Wcast-align -Wshadow -Wwrite-strings -Wswitch-default -Wno-unused-parameter" +export CXXFLAGS+=" -Wno-empty-body -fomit-frame-pointer -fno-optimize-sibling-calls" +export CXXFLAGS+=" -fno-strict-aliasing -fno-unroll-loops -fsigned-char -fstrict-overflow" +export CXXFLAGS+=" -Wnon-virtual-dtor -std=c++0x" + +cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DMAJORVER=${MAJORVER} -DFULLVER=%{version} +make %{?jobs:-j%jobs} + +%install +rm -rf %{buildroot} +%make_install + + +%post +/sbin/ldconfig + +%files +%manifest packaging/%{name}.manifest +%{_libdir}/lib%{name}-client.so* +%{_libdir}/lib%{name}-server.so* +%license LICENSE + + +%preun genuine +echo "You need to reinstall %{name} to keep using the APIs after uninstalling this." + +%post genuine +pushd %{_libdir} +ln -sf lib%{name}-client-genuine.so.%{version} lib%{name}-client.so.%{version} +ln -sf lib%{name}-server-genuine.so.%{version} lib%{name}-server.so.%{version} +chsmack -a "_" lib%{name}-client.so.%{version} +chsmack -a "_" lib%{name}-server.so.%{version} +popd +/sbin/ldconfig + +%files genuine +%manifest packaging/%{name}.manifest +%{_libdir}/lib%{name}-client-genuine.so* +%{_libdir}/lib%{name}-server-genuine.so* + + +%files devel +%{_includedir}/context-service/*.h +%{_libdir}/pkgconfig/*.pc diff --git a/src/client-dummy/CMakeLists.txt b/src/client-dummy/CMakeLists.txt new file mode 100644 index 0000000..f293fd7 --- /dev/null +++ b/src/client-dummy/CMakeLists.txt @@ -0,0 +1,34 @@ +SET(target "${PROJECT_NAME}-client") + +SET(DEPS "${DEPS} context-common-client") + +FILE(GLOB_RECURSE SRCS *.cpp) +MESSAGE("Sources: ${SRCS}") + +INCLUDE(FindPkgConfig) +pkg_check_modules(PKG_CLIENT REQUIRED ${DEPS}) + +FOREACH(flag ${PKG_CLIENT_CFLAGS}) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}") +ENDFOREACH(flag) + +ADD_LIBRARY(${target} SHARED ${SRCS}) +TARGET_LINK_LIBRARIES(${target} ${PKG_CLIENT_LDFLAGS}) +SET_TARGET_PROPERTIES(${target} PROPERTIES SOVERSION ${MAJORVER}) +SET_TARGET_PROPERTIES(${target} PROPERTIES VERSION ${FULLVER}) + + +SET(PC_NAME ${target}) +SET(PC_DESCRIPTION "Tizen Context Store Client Library") +SET(PC_REQUIRED ${DEPS}) +SET(PC_LDFLAGS -l${target}) + +CONFIGURE_FILE( + ${CMAKE_SOURCE_DIR}/${PROJECT_NAME}.pc.in + ${CMAKE_SOURCE_DIR}/${target}.pc + @ONLY +) + + +INSTALL(TARGETS ${target} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/${target}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) diff --git a/src/client-dummy/TestAPI.cpp b/src/client-dummy/TestAPI.cpp new file mode 100644 index 0000000..cc3040d --- /dev/null +++ b/src/client-dummy/TestAPI.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * 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 +#include + +using namespace ctx; + +/* TODO: Remove this test code */ +EXPORT_API int context_store_test() +{ + return E_SUPPORT; +} diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt new file mode 100644 index 0000000..8f551d7 --- /dev/null +++ b/src/client/CMakeLists.txt @@ -0,0 +1,19 @@ +SET(target "${PROJECT_NAME}-client-genuine") + +SET(DEPS "${DEPS} context-common-client") + +FILE(GLOB_RECURSE SRCS *.cpp ../shared/*.cpp) +MESSAGE("Sources: ${SRCS}") + +INCLUDE(FindPkgConfig) +pkg_check_modules(PKG_CLIENT REQUIRED ${DEPS}) + +FOREACH(flag ${PKG_CLIENT_CFLAGS}) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}") +ENDFOREACH(flag) + +ADD_LIBRARY(${target} SHARED ${SRCS}) +TARGET_LINK_LIBRARIES(${target} ${PKG_CLIENT_LDFLAGS}) +SET_TARGET_PROPERTIES(${target} PROPERTIES VERSION ${FULLVER}) + +INSTALL(TARGETS ${target} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} NAMELINK_SKIP) diff --git a/src/client/TestAPI.cpp b/src/client/TestAPI.cpp new file mode 100644 index 0000000..cf90d18 --- /dev/null +++ b/src/client/TestAPI.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * 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 +#include +#include + +using namespace ctx; + +/* TODO: Remove this test code */ +EXPORT_API int context_store_test() +{ + // DBusClient object can be maintained as a static object. + DBusClient client(CTX_CONTEXT_STORE); + + GVariant* output = NULL; + + int err = client.call("test", g_variant_new("(i)", 100), &output); + + _I(YELLOW("Return: %d (%s)"), err, CTX_ERROR_STR(err)); + + return err; +} diff --git a/src/server-dummy/CMakeLists.txt b/src/server-dummy/CMakeLists.txt new file mode 100644 index 0000000..211ad0e --- /dev/null +++ b/src/server-dummy/CMakeLists.txt @@ -0,0 +1,34 @@ +SET(target "${PROJECT_NAME}-server") + +SET(DEPS "${DEPS} context-common-server") + +FILE(GLOB_RECURSE SRCS *.cpp) +MESSAGE("Sources: ${SRCS}") + +INCLUDE(FindPkgConfig) +pkg_check_modules(PKG_SERVER REQUIRED ${DEPS}) + +FOREACH(flag ${PKG_SERVER_CFLAGS}) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}") +ENDFOREACH(flag) + +ADD_LIBRARY(${target} SHARED ${SRCS}) +TARGET_LINK_LIBRARIES(${target} ${PKG_SERVER_LDFLAGS}) +SET_TARGET_PROPERTIES(${target} PROPERTIES SOVERSION ${MAJORVER}) +SET_TARGET_PROPERTIES(${target} PROPERTIES VERSION ${FULLVER}) + + +SET(PC_NAME ${target}) +SET(PC_DESCRIPTION "Tizen Context Store Server Library") +SET(PC_REQUIRED ${DEPS}) +SET(PC_LDFLAGS -l${target}) + +CONFIGURE_FILE( + ${CMAKE_SOURCE_DIR}/${PROJECT_NAME}.pc.in + ${CMAKE_SOURCE_DIR}/${target}.pc + @ONLY +) + + +INSTALL(TARGETS ${target} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/${target}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) diff --git a/src/server-dummy/ContextStoreService.cpp b/src/server-dummy/ContextStoreService.cpp new file mode 100644 index 0000000..3b58047 --- /dev/null +++ b/src/server-dummy/ContextStoreService.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * 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 +#include + +using namespace ctx; + +ContextStoreService::ContextStoreService(GDBusConnection* conn) : + DBusService(conn, CTX_CONTEXT_STORE, CTX_CONTEXT_STORE_SPEC) +{ + throw std::runtime_error("Context Store is not supported"); +} + +ContextStoreService::~ContextStoreService() +{ +} + +void ContextStoreService::prepare() +{ +} + +ClientProxy* ContextStoreService::createProxy(const std::string& busName) +{ + return NULL; +} diff --git a/src/server/CMakeLists.txt b/src/server/CMakeLists.txt new file mode 100644 index 0000000..64a741f --- /dev/null +++ b/src/server/CMakeLists.txt @@ -0,0 +1,19 @@ +SET(target "${PROJECT_NAME}-server-genuine") + +SET(DEPS "${DEPS} context-common-server") + +FILE(GLOB_RECURSE SRCS *.cpp ../shared/*.cpp) +MESSAGE("Sources: ${SRCS}") + +INCLUDE(FindPkgConfig) +pkg_check_modules(PKG_SERVER REQUIRED ${DEPS}) + +FOREACH(flag ${PKG_SERVER_CFLAGS}) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}") +ENDFOREACH(flag) + +ADD_LIBRARY(${target} SHARED ${SRCS}) +TARGET_LINK_LIBRARIES(${target} ${PKG_SERVER_LDFLAGS}) +SET_TARGET_PROPERTIES(${target} PROPERTIES VERSION ${FULLVER}) + +INSTALL(TARGETS ${target} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} NAMELINK_SKIP) diff --git a/src/server/ContextStoreClientProxy.cpp b/src/server/ContextStoreClientProxy.cpp new file mode 100644 index 0000000..bf86158 --- /dev/null +++ b/src/server/ContextStoreClientProxy.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * 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 +#include +#include "ContextStoreClientProxy.h" + +using namespace ctx; + +ContextStoreClientProxy::ContextStoreClientProxy(DBusService* hostService, const std::string& busName) : + ClientProxy(hostService, busName) +{ +} + +ContextStoreClientProxy::~ContextStoreClientProxy() +{ +} + +void ContextStoreClientProxy::onMethodCalled(MethodCall* methodCall) +{ + /* TODO: Remove this test code */ + char* param = g_variant_print(methodCall->getParam(), FALSE); + _I("Caller: %s, Method: %s", methodCall->getSender()->getBusName().c_str(), methodCall->getMethodName().c_str()); + _I("Parameters: %s", param); + g_free(param); + methodCall->reply(E_FAILED); + delete methodCall; +} + +void ContextStoreClientProxy::onDisconnected() +{ +} diff --git a/src/server/ContextStoreClientProxy.h b/src/server/ContextStoreClientProxy.h new file mode 100644 index 0000000..eaff6d6 --- /dev/null +++ b/src/server/ContextStoreClientProxy.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * 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 __CONTEXT_STORE_CLIENT_PROXY_H__ +#define __CONTEXT_STORE_CLIENT_PROXY_H__ + +#include + +namespace ctx { + + class ContextStoreClientProxy : public ClientProxy { + public: + ContextStoreClientProxy(DBusService* hostService, const std::string& busName); + ~ContextStoreClientProxy(); + + void onMethodCalled(MethodCall* methodCall); + void onDisconnected(); + }; + +} + +#endif /* __CONTEXT_STORE_CLIENT_PROXY_H__ */ diff --git a/src/server/ContextStoreService.cpp b/src/server/ContextStoreService.cpp new file mode 100644 index 0000000..d9c9d04 --- /dev/null +++ b/src/server/ContextStoreService.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * 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 +#include +#include "ContextStoreClientProxy.h" + +using namespace ctx; + +ContextStoreService::ContextStoreService(GDBusConnection* conn) : + DBusService(conn, CTX_CONTEXT_STORE, CTX_CONTEXT_STORE_SPEC) +{ +} + +ContextStoreService::~ContextStoreService() +{ +} + +void ContextStoreService::prepare() +{ + /* Service-specific initialization tasks */ +} + +ClientProxy* ContextStoreService::createProxy(const std::string& busName) +{ + return new(std::nothrow) ContextStoreClientProxy(this, busName); +} diff --git a/src/shared/ContextStoreTypesPrivate.h b/src/shared/ContextStoreTypesPrivate.h new file mode 100644 index 0000000..e41b3e5 --- /dev/null +++ b/src/shared/ContextStoreTypesPrivate.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * 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 __CONTEXT_STORE_TYPES_PRIVATE_H__ +#define __CONTEXT_STORE_TYPES_PRIVATE_H__ + +#include + +#define CTX_CONTEXT_STORE "ContextStore" +#define CTX_CONTEXT_STORE_SPEC \ + "" \ + " " \ + " " \ + "" + +#endif -- 2.7.4 From dea4385a7137ed688c58d8acf5579e3a7fbae9b3 Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Fri, 10 Feb 2017 11:08:39 +0900 Subject: [PATCH 02/16] Cleanup the test code Change-Id: If98b88f8531192bfe34e3835ad713935c24ec8ba Signed-off-by: Mu-Woong Lee --- include/{TestAPI.h => ContextStore.h} | 5 +++-- src/client-dummy/{TestAPI.cpp => ContextStore.cpp} | 2 +- src/client/{TestAPI.cpp => ContextStore.cpp} | 5 ++++- src/server/ContextStoreClientProxy.cpp | 7 +------ 4 files changed, 9 insertions(+), 10 deletions(-) rename include/{TestAPI.h => ContextStore.h} (91%) rename src/client-dummy/{TestAPI.cpp => ContextStore.cpp} (96%) rename src/client/{TestAPI.cpp => ContextStore.cpp} (93%) diff --git a/include/TestAPI.h b/include/ContextStore.h similarity index 91% rename from include/TestAPI.h rename to include/ContextStore.h index 66b9257..e68578a 100644 --- a/include/TestAPI.h +++ b/include/ContextStore.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __CONTEXT_STORE_TEST_API_H__ -#define __CONTEXT_STORE_TEST_API_H__ +#ifndef __CONTEXT_STORE_H__ +#define __CONTEXT_STORE_H__ #include @@ -24,6 +24,7 @@ extern "C" { #endif +/* TEST CODE */ int context_store_test(); #ifdef __cplusplus diff --git a/src/client-dummy/TestAPI.cpp b/src/client-dummy/ContextStore.cpp similarity index 96% rename from src/client-dummy/TestAPI.cpp rename to src/client-dummy/ContextStore.cpp index cc3040d..c526a34 100644 --- a/src/client-dummy/TestAPI.cpp +++ b/src/client-dummy/ContextStore.cpp @@ -15,7 +15,7 @@ */ #include -#include +#include using namespace ctx; diff --git a/src/client/TestAPI.cpp b/src/client/ContextStore.cpp similarity index 93% rename from src/client/TestAPI.cpp rename to src/client/ContextStore.cpp index cf90d18..97f42ab 100644 --- a/src/client/TestAPI.cpp +++ b/src/client/ContextStore.cpp @@ -16,7 +16,7 @@ #include #include -#include +#include using namespace ctx; @@ -32,5 +32,8 @@ EXPORT_API int context_store_test() _I(YELLOW("Return: %d (%s)"), err, CTX_ERROR_STR(err)); + if (output) + g_variant_unref(output); + return err; } diff --git a/src/server/ContextStoreClientProxy.cpp b/src/server/ContextStoreClientProxy.cpp index bf86158..d4ea4b1 100644 --- a/src/server/ContextStoreClientProxy.cpp +++ b/src/server/ContextStoreClientProxy.cpp @@ -31,12 +31,7 @@ ContextStoreClientProxy::~ContextStoreClientProxy() void ContextStoreClientProxy::onMethodCalled(MethodCall* methodCall) { - /* TODO: Remove this test code */ - char* param = g_variant_print(methodCall->getParam(), FALSE); - _I("Caller: %s, Method: %s", methodCall->getSender()->getBusName().c_str(), methodCall->getMethodName().c_str()); - _I("Parameters: %s", param); - g_free(param); - methodCall->reply(E_FAILED); + // 'methodCall' should be deleted. delete methodCall; } -- 2.7.4 From 1033edc247aa29ce413a2461273102af2a40c687 Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Mon, 20 Feb 2017 12:49:40 +0900 Subject: [PATCH 03/16] Cleanup the build script Change-Id: I60fbf688dea6a0f73467b939f4da36a27a72d801 Signed-off-by: Mu-Woong Lee --- packaging/context-store.spec | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packaging/context-store.spec b/packaging/context-store.spec index 5cb13b7..235067e 100644 --- a/packaging/context-store.spec +++ b/packaging/context-store.spec @@ -29,6 +29,7 @@ Requires: %{name} = %{version}-%{release} Requires: context-service Provides: %{name}-profile_mobile = %{version}-%{release} Provides: %{name}-profile_wearable = %{version}-%{release} +%global __provides_exclude ^.*-genuine\\.so.*$ %description genuine Binary replacement for context-store. @@ -56,11 +57,10 @@ export CXXFLAGS+=" -Wno-empty-body -fomit-frame-pointer -fno-optimize-sibling-ca export CXXFLAGS+=" -fno-strict-aliasing -fno-unroll-loops -fsigned-char -fstrict-overflow" export CXXFLAGS+=" -Wnon-virtual-dtor -std=c++0x" -cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DMAJORVER=${MAJORVER} -DFULLVER=%{version} -make %{?jobs:-j%jobs} +%cmake . -DMAJORVER=${MAJORVER} -DFULLVER=%{version} +make %{?_smp_mflags} %install -rm -rf %{buildroot} %make_install -- 2.7.4 From c62d80d7cb08243e55c7d1c2cf162738950c1085 Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Mon, 20 Feb 2017 15:04:06 +0900 Subject: [PATCH 04/16] Implement the virtual functions added to the DBusService class Change-Id: I877e4862859cef9116a2bfd8b0e56714b4ded2b5 Signed-off-by: Mu-Woong Lee --- include/ContextStoreService.h | 4 +++- src/server-dummy/ContextStoreService.cpp | 11 ++++++++++- src/server/ContextStoreService.cpp | 11 ++++++++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/include/ContextStoreService.h b/include/ContextStoreService.h index 209c1f2..e8a976b 100644 --- a/include/ContextStoreService.h +++ b/include/ContextStoreService.h @@ -30,7 +30,9 @@ namespace ctx { ~ContextStoreService(); protected: - void prepare(); + bool prepare(); + void cleanup(); + void onUserActivated(uid_t uid); ClientProxy* createProxy(const std::string& busName); }; diff --git a/src/server-dummy/ContextStoreService.cpp b/src/server-dummy/ContextStoreService.cpp index 3b58047..c0d8092 100644 --- a/src/server-dummy/ContextStoreService.cpp +++ b/src/server-dummy/ContextStoreService.cpp @@ -29,7 +29,16 @@ ContextStoreService::~ContextStoreService() { } -void ContextStoreService::prepare() +bool ContextStoreService::prepare() +{ + return false; +} + +void ContextStoreService::cleanup() +{ +} + +void ContextStoreService::onUserActivated(uid_t uid) { } diff --git a/src/server/ContextStoreService.cpp b/src/server/ContextStoreService.cpp index d9c9d04..7abe338 100644 --- a/src/server/ContextStoreService.cpp +++ b/src/server/ContextStoreService.cpp @@ -29,9 +29,18 @@ ContextStoreService::~ContextStoreService() { } -void ContextStoreService::prepare() +bool ContextStoreService::prepare() { /* Service-specific initialization tasks */ + return true; +} + +void ContextStoreService::cleanup() +{ +} + +void ContextStoreService::onUserActivated(uid_t uid) +{ } ClientProxy* ContextStoreService::createProxy(const std::string& busName) -- 2.7.4 From 7e262b89b38c9cfd19b0b310a3774cfee78a8c02 Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Mon, 20 Feb 2017 17:14:06 +0900 Subject: [PATCH 05/16] Apply updated class names Change-Id: I58d902b49d3be20a17f801bb0689c41342e58181 Signed-off-by: Mu-Woong Lee --- include/ContextStoreService.h | 6 +++--- src/client/ContextStore.cpp | 8 ++++---- src/server-dummy/ContextStoreService.cpp | 4 ++-- ...{ContextStoreClientProxy.cpp => ContextStoreClient.cpp} | 14 +++++++------- .../{ContextStoreClientProxy.h => ContextStoreClient.h} | 14 +++++++------- src/server/ContextStoreService.cpp | 8 ++++---- 6 files changed, 27 insertions(+), 27 deletions(-) rename src/server/{ContextStoreClientProxy.cpp => ContextStoreClient.cpp} (66%) rename src/server/{ContextStoreClientProxy.h => ContextStoreClient.h} (69%) diff --git a/include/ContextStoreService.h b/include/ContextStoreService.h index e8a976b..a599af9 100644 --- a/include/ContextStoreService.h +++ b/include/ContextStoreService.h @@ -19,12 +19,12 @@ /* This header SHOULD NOT be included by other headers in this directory. */ -#include +#include #include namespace ctx { - class EXPORT_API ContextStoreService : public DBusService { + class EXPORT_API ContextStoreService : public ServiceBase { public: ContextStoreService(GDBusConnection* conn); ~ContextStoreService(); @@ -33,7 +33,7 @@ namespace ctx { bool prepare(); void cleanup(); void onUserActivated(uid_t uid); - ClientProxy* createProxy(const std::string& busName); + ClientBase* createClient(const std::string& busName); }; } diff --git a/src/client/ContextStore.cpp b/src/client/ContextStore.cpp index 97f42ab..051a48d 100644 --- a/src/client/ContextStore.cpp +++ b/src/client/ContextStore.cpp @@ -15,7 +15,7 @@ */ #include -#include +#include #include using namespace ctx; @@ -23,12 +23,12 @@ using namespace ctx; /* TODO: Remove this test code */ EXPORT_API int context_store_test() { - // DBusClient object can be maintained as a static object. - DBusClient client(CTX_CONTEXT_STORE); + // ServiceProxy object can be maintained as a static object. + ServiceProxy proxy(CTX_CONTEXT_STORE); GVariant* output = NULL; - int err = client.call("test", g_variant_new("(i)", 100), &output); + int err = proxy.call("test", g_variant_new("(i)", 100), &output); _I(YELLOW("Return: %d (%s)"), err, CTX_ERROR_STR(err)); diff --git a/src/server-dummy/ContextStoreService.cpp b/src/server-dummy/ContextStoreService.cpp index c0d8092..3c66f49 100644 --- a/src/server-dummy/ContextStoreService.cpp +++ b/src/server-dummy/ContextStoreService.cpp @@ -20,7 +20,7 @@ using namespace ctx; ContextStoreService::ContextStoreService(GDBusConnection* conn) : - DBusService(conn, CTX_CONTEXT_STORE, CTX_CONTEXT_STORE_SPEC) + ServiceBase(conn, CTX_CONTEXT_STORE, CTX_CONTEXT_STORE_SPEC) { throw std::runtime_error("Context Store is not supported"); } @@ -42,7 +42,7 @@ void ContextStoreService::onUserActivated(uid_t uid) { } -ClientProxy* ContextStoreService::createProxy(const std::string& busName) +ClientBase* ContextStoreService::createClient(const std::string& busName) { return NULL; } diff --git a/src/server/ContextStoreClientProxy.cpp b/src/server/ContextStoreClient.cpp similarity index 66% rename from src/server/ContextStoreClientProxy.cpp rename to src/server/ContextStoreClient.cpp index d4ea4b1..6f64c7f 100644 --- a/src/server/ContextStoreClientProxy.cpp +++ b/src/server/ContextStoreClient.cpp @@ -14,27 +14,27 @@ * limitations under the License. */ -#include +#include #include -#include "ContextStoreClientProxy.h" +#include "ContextStoreClient.h" using namespace ctx; -ContextStoreClientProxy::ContextStoreClientProxy(DBusService* hostService, const std::string& busName) : - ClientProxy(hostService, busName) +ContextStoreClient::ContextStoreClient(ServiceBase* hostService, const std::string& busName) : + ClientBase(hostService, busName) { } -ContextStoreClientProxy::~ContextStoreClientProxy() +ContextStoreClient::~ContextStoreClient() { } -void ContextStoreClientProxy::onMethodCalled(MethodCall* methodCall) +void ContextStoreClient::onMethodCalled(MethodCall* methodCall) { // 'methodCall' should be deleted. delete methodCall; } -void ContextStoreClientProxy::onDisconnected() +void ContextStoreClient::onDisconnected() { } diff --git a/src/server/ContextStoreClientProxy.h b/src/server/ContextStoreClient.h similarity index 69% rename from src/server/ContextStoreClientProxy.h rename to src/server/ContextStoreClient.h index eaff6d6..0f51a77 100644 --- a/src/server/ContextStoreClientProxy.h +++ b/src/server/ContextStoreClient.h @@ -14,17 +14,17 @@ * limitations under the License. */ -#ifndef __CONTEXT_STORE_CLIENT_PROXY_H__ -#define __CONTEXT_STORE_CLIENT_PROXY_H__ +#ifndef __CONTEXT_STORE_CLIENT_H__ +#define __CONTEXT_STORE_CLIENT_H__ -#include +#include namespace ctx { - class ContextStoreClientProxy : public ClientProxy { + class ContextStoreClient : public ClientBase { public: - ContextStoreClientProxy(DBusService* hostService, const std::string& busName); - ~ContextStoreClientProxy(); + ContextStoreClient(ServiceBase* hostService, const std::string& busName); + ~ContextStoreClient(); void onMethodCalled(MethodCall* methodCall); void onDisconnected(); @@ -32,4 +32,4 @@ namespace ctx { } -#endif /* __CONTEXT_STORE_CLIENT_PROXY_H__ */ +#endif /* __CONTEXT_STORE_CLIENT_H__ */ diff --git a/src/server/ContextStoreService.cpp b/src/server/ContextStoreService.cpp index 7abe338..e435fd0 100644 --- a/src/server/ContextStoreService.cpp +++ b/src/server/ContextStoreService.cpp @@ -16,12 +16,12 @@ #include #include -#include "ContextStoreClientProxy.h" +#include "ContextStoreClient.h" using namespace ctx; ContextStoreService::ContextStoreService(GDBusConnection* conn) : - DBusService(conn, CTX_CONTEXT_STORE, CTX_CONTEXT_STORE_SPEC) + ServiceBase(conn, CTX_CONTEXT_STORE, CTX_CONTEXT_STORE_SPEC) { } @@ -43,7 +43,7 @@ void ContextStoreService::onUserActivated(uid_t uid) { } -ClientProxy* ContextStoreService::createProxy(const std::string& busName) +ClientBase* ContextStoreService::createClient(const std::string& busName) { - return new(std::nothrow) ContextStoreClientProxy(this, busName); + return new(std::nothrow) ContextStoreClient(this, busName); } -- 2.7.4 From d17fb23f8ccbbf704a1d9737aae9a6190b78de7d Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Tue, 21 Feb 2017 09:47:28 +0900 Subject: [PATCH 06/16] Sync with the header separation in context-common Change-Id: I70591a1167e6db3c068dbcb8519ffcb513830f20 Signed-off-by: Mu-Woong Lee --- src/shared/ContextStoreTypesPrivate.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/shared/ContextStoreTypesPrivate.h b/src/shared/ContextStoreTypesPrivate.h index e41b3e5..abcbbe0 100644 --- a/src/shared/ContextStoreTypesPrivate.h +++ b/src/shared/ContextStoreTypesPrivate.h @@ -18,6 +18,7 @@ #define __CONTEXT_STORE_TYPES_PRIVATE_H__ #include +#include #define CTX_CONTEXT_STORE "ContextStore" #define CTX_CONTEXT_STORE_SPEC \ -- 2.7.4 From 5a22236b65947b88b06fd9f8cb9c12343182c815 Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Thu, 2 Mar 2017 15:06:00 +0900 Subject: [PATCH 07/16] Fix the build scripts to be sure that each dummy uses its own pkg check parameter Change-Id: I323f97c05a5204ba1b924bd017595eac370c6a31 Signed-off-by: Mu-Woong Lee --- src/client-dummy/CMakeLists.txt | 6 +++--- src/server-dummy/CMakeLists.txt | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/client-dummy/CMakeLists.txt b/src/client-dummy/CMakeLists.txt index f293fd7..f247700 100644 --- a/src/client-dummy/CMakeLists.txt +++ b/src/client-dummy/CMakeLists.txt @@ -6,14 +6,14 @@ FILE(GLOB_RECURSE SRCS *.cpp) MESSAGE("Sources: ${SRCS}") INCLUDE(FindPkgConfig) -pkg_check_modules(PKG_CLIENT REQUIRED ${DEPS}) +pkg_check_modules(PKG_CLIENT_DUMMY REQUIRED ${DEPS}) -FOREACH(flag ${PKG_CLIENT_CFLAGS}) +FOREACH(flag ${PKG_CLIENT_DUMMY_CFLAGS}) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}") ENDFOREACH(flag) ADD_LIBRARY(${target} SHARED ${SRCS}) -TARGET_LINK_LIBRARIES(${target} ${PKG_CLIENT_LDFLAGS}) +TARGET_LINK_LIBRARIES(${target} ${PKG_CLIENT_DUMMY_LDFLAGS}) SET_TARGET_PROPERTIES(${target} PROPERTIES SOVERSION ${MAJORVER}) SET_TARGET_PROPERTIES(${target} PROPERTIES VERSION ${FULLVER}) diff --git a/src/server-dummy/CMakeLists.txt b/src/server-dummy/CMakeLists.txt index 211ad0e..d5a3a4d 100644 --- a/src/server-dummy/CMakeLists.txt +++ b/src/server-dummy/CMakeLists.txt @@ -6,14 +6,14 @@ FILE(GLOB_RECURSE SRCS *.cpp) MESSAGE("Sources: ${SRCS}") INCLUDE(FindPkgConfig) -pkg_check_modules(PKG_SERVER REQUIRED ${DEPS}) +pkg_check_modules(PKG_SERVER_DUMMY REQUIRED ${DEPS}) -FOREACH(flag ${PKG_SERVER_CFLAGS}) +FOREACH(flag ${PKG_SERVER_DUMMY_CFLAGS}) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}") ENDFOREACH(flag) ADD_LIBRARY(${target} SHARED ${SRCS}) -TARGET_LINK_LIBRARIES(${target} ${PKG_SERVER_LDFLAGS}) +TARGET_LINK_LIBRARIES(${target} ${PKG_SERVER_DUMMY_LDFLAGS}) SET_TARGET_PROPERTIES(${target} PROPERTIES SOVERSION ${MAJORVER}) SET_TARGET_PROPERTIES(${target} PROPERTIES VERSION ${FULLVER}) -- 2.7.4 From a02279f1cf0cef36d0d13d3e213c1c15b05e35ef Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Fri, 3 Mar 2017 20:05:37 +0900 Subject: [PATCH 08/16] Update the service code skeleton w.r.t. the change of the active user monitoring scheme Change-Id: Iad79d4539e2ea668954acf1343296e6a01fef286 Signed-off-by: Mu-Woong Lee --- include/ContextStoreService.h | 7 ++++++- src/server-dummy/ContextStoreService.cpp | 15 ++++++++++++--- src/server/ContextStoreService.cpp | 15 ++++++++++++--- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/include/ContextStoreService.h b/include/ContextStoreService.h index a599af9..ca384dc 100644 --- a/include/ContextStoreService.h +++ b/include/ContextStoreService.h @@ -29,11 +29,16 @@ namespace ctx { ContextStoreService(GDBusConnection* conn); ~ContextStoreService(); + bool isUserService(); + protected: bool prepare(); void cleanup(); - void onUserActivated(uid_t uid); + ClientBase* createClient(const std::string& busName); + + void onUserActivated(); + void onUserDeactivated(); }; } diff --git a/src/server-dummy/ContextStoreService.cpp b/src/server-dummy/ContextStoreService.cpp index 3c66f49..d5ef3b2 100644 --- a/src/server-dummy/ContextStoreService.cpp +++ b/src/server-dummy/ContextStoreService.cpp @@ -29,16 +29,17 @@ ContextStoreService::~ContextStoreService() { } -bool ContextStoreService::prepare() +bool ContextStoreService::isUserService() { return false; } -void ContextStoreService::cleanup() +bool ContextStoreService::prepare() { + return false; } -void ContextStoreService::onUserActivated(uid_t uid) +void ContextStoreService::cleanup() { } @@ -46,3 +47,11 @@ ClientBase* ContextStoreService::createClient(const std::string& busName) { return NULL; } + +void ContextStoreService::onUserActivated() +{ +} + +void ContextStoreService::onUserDeactivated() +{ +} diff --git a/src/server/ContextStoreService.cpp b/src/server/ContextStoreService.cpp index e435fd0..c8dce21 100644 --- a/src/server/ContextStoreService.cpp +++ b/src/server/ContextStoreService.cpp @@ -29,6 +29,11 @@ ContextStoreService::~ContextStoreService() { } +bool ContextStoreService::isUserService() +{ + return false; +} + bool ContextStoreService::prepare() { /* Service-specific initialization tasks */ @@ -39,11 +44,15 @@ void ContextStoreService::cleanup() { } -void ContextStoreService::onUserActivated(uid_t uid) +ClientBase* ContextStoreService::createClient(const std::string& busName) +{ + return new(std::nothrow) ContextStoreClient(this, busName); +} + +void ContextStoreService::onUserActivated() { } -ClientBase* ContextStoreService::createClient(const std::string& busName) +void ContextStoreService::onUserDeactivated() { - return new(std::nothrow) ContextStoreClient(this, busName); } -- 2.7.4 From 2f8d2a5d198c923b9453407b53b2631a625527eb Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Thu, 23 Feb 2017 22:54:34 +0900 Subject: [PATCH 09/16] Define ContextStore C++ internal API (skeleton) Change-Id: I3b2f701932d8d27e21013b29bf8e20103b2b9c40 Signed-off-by: Mu-Woong Lee --- include/ContextStore.h | 26 +++++--- include/ContextStoreManager.h | 37 +++++++++++ include/ContextStoreSearchQuery.h | 52 +++++++++++++++ src/client-dummy/ContextStore.cpp | 26 +++++++- src/client-dummy/ContextStoreManager.cpp | 38 +++++++++++ src/client-dummy/ContextStoreSearchQuery.cpp | 65 ++++++++++++++++++ src/client/AppManagedLocalStore.cpp | 58 ++++++++++++++++ src/client/AppManagedLocalStore.h | 44 +++++++++++++ src/client/AppManagedSharedStore.cpp | 49 ++++++++++++++ src/client/AppManagedSharedStore.h | 42 ++++++++++++ src/client/AppManagedStore.cpp | 34 ++++++++++ src/client/AppManagedStore.h | 40 ++++++++++++ src/client/ContextStore.cpp | 31 +++++---- src/client/ContextStoreManager.cpp | 98 ++++++++++++++++++++++++++++ src/client/ContextStoreSearchQuery.cpp | 66 +++++++++++++++++++ src/client/PlatformManagedStore.cpp | 64 ++++++++++++++++++ src/client/PlatformManagedStore.h | 47 +++++++++++++ src/client/Schema.cpp | 27 ++++++++ src/client/Schema.h | 37 +++++++++++ src/client/SchemaConf.cpp | 38 +++++++++++ src/client/SchemaConf.h | 38 +++++++++++ src/shared/ContextStoreTypesPrivate.h | 1 + 22 files changed, 936 insertions(+), 22 deletions(-) create mode 100644 include/ContextStoreManager.h create mode 100644 include/ContextStoreSearchQuery.h create mode 100644 src/client-dummy/ContextStoreManager.cpp create mode 100644 src/client-dummy/ContextStoreSearchQuery.cpp create mode 100644 src/client/AppManagedLocalStore.cpp create mode 100644 src/client/AppManagedLocalStore.h create mode 100644 src/client/AppManagedSharedStore.cpp create mode 100644 src/client/AppManagedSharedStore.h create mode 100644 src/client/AppManagedStore.cpp create mode 100644 src/client/AppManagedStore.h create mode 100644 src/client/ContextStoreManager.cpp create mode 100644 src/client/ContextStoreSearchQuery.cpp create mode 100644 src/client/PlatformManagedStore.cpp create mode 100644 src/client/PlatformManagedStore.h create mode 100644 src/client/Schema.cpp create mode 100644 src/client/Schema.h create mode 100644 src/client/SchemaConf.cpp create mode 100644 src/client/SchemaConf.h diff --git a/include/ContextStore.h b/include/ContextStore.h index e68578a..cfe97d1 100644 --- a/include/ContextStore.h +++ b/include/ContextStore.h @@ -17,18 +17,26 @@ #ifndef __CONTEXT_STORE_H__ #define __CONTEXT_STORE_H__ +#include +#include #include +#include -#ifdef __cplusplus -extern "C" -{ -#endif +namespace ctx { -/* TEST CODE */ -int context_store_test(); + class EXPORT_API ContextStore { + public: + virtual ~ContextStore(); + + virtual int insert(const std::vector& columns, Tuple& record); + virtual int insert(const std::vector& columns, std::vector& records); + virtual int retrieve(const ContextStoreSearchQuery& query, std::vector& result); + virtual int remove(const std::string& selection); + + protected: + ContextStore(); + }; -#ifdef __cplusplus } -#endif -#endif +#endif /* __CONTEXT_STORE_H__ */ diff --git a/include/ContextStoreManager.h b/include/ContextStoreManager.h new file mode 100644 index 0000000..4fbdcdc --- /dev/null +++ b/include/ContextStoreManager.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * 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 __CONTEXT_STORE_MANAGER_H__ +#define __CONTEXT_STORE_MANAGER_H__ + +#include +#include +#include + +namespace ctx { + + class EXPORT_API ContextStoreManager { + public: + ContextStoreManager(); + ~ContextStoreManager(); + + int getStore(const std::string& uri, ContextStore** contextStore); + int removeStore(const std::string& uri); + }; + +} + +#endif /* __CONTEXT_STORE_MANAGER_H__ */ diff --git a/include/ContextStoreSearchQuery.h b/include/ContextStoreSearchQuery.h new file mode 100644 index 0000000..2c0d187 --- /dev/null +++ b/include/ContextStoreSearchQuery.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * 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 __CONTEXT_STORE_SEARCH_QUERY_H__ +#define __CONTEXT_STORE_SEARCH_QUERY_H__ + +#include +#include + +namespace ctx { + + class EXPORT_API ContextStoreSearchQuery { + public: + ContextStoreSearchQuery(); + ContextStoreSearchQuery( + const std::string& projection, + const std::string& selection, + const std::string& sortOrder, + unsigned int limit); + + ~ContextStoreSearchQuery(); + + ContextStoreSearchQuery& setProjection(const std::string& projection); + ContextStoreSearchQuery& setSelection(const std::string& selection); + ContextStoreSearchQuery& setSortOrder(const std::string& sortOrder); + ContextStoreSearchQuery& setLimit(unsigned int limit); + + bool valid(); + + private: + std::string __projection; + std::string __selection; + std::string __sortOrder; + unsigned int __limit; + }; + +} + +#endif /* __CONTEXT_STORE_SEARCH_QUERY_H__ */ diff --git a/src/client-dummy/ContextStore.cpp b/src/client-dummy/ContextStore.cpp index c526a34..47eca13 100644 --- a/src/client-dummy/ContextStore.cpp +++ b/src/client-dummy/ContextStore.cpp @@ -19,8 +19,30 @@ using namespace ctx; -/* TODO: Remove this test code */ -EXPORT_API int context_store_test() +ContextStore::ContextStore() +{ +} + +ContextStore::~ContextStore() +{ +} + +int ContextStore::insert(const std::vector& columns, Tuple& record) +{ + return E_SUPPORT; +} + +int ContextStore::insert(const std::vector& columns, std::vector& records) +{ + return E_SUPPORT; +} + +int ContextStore::retrieve(const ContextStoreSearchQuery& query, std::vector& result) +{ + return E_SUPPORT; +} + +int ContextStore::remove(const std::string& selection) { return E_SUPPORT; } diff --git a/src/client-dummy/ContextStoreManager.cpp b/src/client-dummy/ContextStoreManager.cpp new file mode 100644 index 0000000..f19a6dc --- /dev/null +++ b/src/client-dummy/ContextStoreManager.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * 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 +#include + +using namespace ctx; + +ContextStoreManager::ContextStoreManager() +{ +} + +ContextStoreManager::~ContextStoreManager() +{ +} + +int ContextStoreManager::getStore(const std::string& uri, ContextStore** store) +{ + return E_SUPPORT; +} + +int ContextStoreManager::removeStore(const std::string& uri) +{ + return E_SUPPORT; +} diff --git a/src/client-dummy/ContextStoreSearchQuery.cpp b/src/client-dummy/ContextStoreSearchQuery.cpp new file mode 100644 index 0000000..25f60d4 --- /dev/null +++ b/src/client-dummy/ContextStoreSearchQuery.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * 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 +#include + +using namespace ctx; + +ContextStoreSearchQuery::ContextStoreSearchQuery() : + __limit(0) +{ +} + +ContextStoreSearchQuery::ContextStoreSearchQuery(const std::string& projection, + const std::string& selection, const std::string& sortOrder, + unsigned int limit) : + __limit(0) +{ +} + +ContextStoreSearchQuery::~ContextStoreSearchQuery() +{ +} + +ContextStoreSearchQuery& ContextStoreSearchQuery::setProjection(const std::string& projection) +{ + __projection = projection; + return *this; +} + +ContextStoreSearchQuery& ContextStoreSearchQuery::setSelection(const std::string& selection) +{ + __selection = selection; + return *this; +} + +ContextStoreSearchQuery& ContextStoreSearchQuery::setSortOrder(const std::string& sortOrder) +{ + __sortOrder = sortOrder; + return *this; +} + +ContextStoreSearchQuery& ContextStoreSearchQuery::setLimit(unsigned int limit) +{ + __limit = limit; + return *this; +} + +bool ContextStoreSearchQuery::valid() +{ + return false; +} diff --git a/src/client/AppManagedLocalStore.cpp b/src/client/AppManagedLocalStore.cpp new file mode 100644 index 0000000..9480c4f --- /dev/null +++ b/src/client/AppManagedLocalStore.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * 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 "AppManagedLocalStore.h" + +using namespace ctx; + +AppManagedLocalStore::AppManagedLocalStore(ServiceProxy* proxy) : + AppManagedStore(proxy) +{ +} + +AppManagedLocalStore::~AppManagedLocalStore() +{ +} + +int AppManagedLocalStore::init(Schema& schema) +{ + //TODO + return E_SUPPORT; +} + +int AppManagedLocalStore::insert(const std::vector& columns, Tuple& record) +{ + //TODO + return E_SUPPORT; +} + +int AppManagedLocalStore::insert(const std::vector& columns, std::vector& records) +{ + //TODO + return E_SUPPORT; +} + +int AppManagedLocalStore::remove(const std::string& selection) +{ + //TODO + return E_SUPPORT; +} + +int AppManagedLocalStore::destroy(const std::string& uri, ServiceProxy* proxy) +{ + //TODO + return E_NONE; +} diff --git a/src/client/AppManagedLocalStore.h b/src/client/AppManagedLocalStore.h new file mode 100644 index 0000000..8ae4cc1 --- /dev/null +++ b/src/client/AppManagedLocalStore.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * 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 __CONTEXT_STORE_APP_MANAGED_LOCAL_STORE_H__ +#define __CONTEXT_STORE_APP_MANAGED_LOCAL_STORE_H__ + +#include +#include +#include +#include "AppManagedStore.h" +#include "Schema.h" + +namespace ctx { + + class AppManagedLocalStore : public AppManagedStore { + public: + AppManagedLocalStore(ServiceProxy* proxy); + ~AppManagedLocalStore(); + + int init(Schema& schema); + + int insert(const std::vector& columns, Tuple& record); + int insert(const std::vector& columns, std::vector& records); + int remove(const std::string& selection); + + static int destroy(const std::string& uri, ServiceProxy* proxy); + }; + +} + +#endif /* __CONTEXT_STORE_APP_MANAGED_LOCAL_STORE_H__ */ diff --git a/src/client/AppManagedSharedStore.cpp b/src/client/AppManagedSharedStore.cpp new file mode 100644 index 0000000..0943d6b --- /dev/null +++ b/src/client/AppManagedSharedStore.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * 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 "AppManagedSharedStore.h" + +using namespace ctx; + +AppManagedSharedStore::AppManagedSharedStore(ServiceProxy* proxy) : + AppManagedStore(proxy) +{ +} + +AppManagedSharedStore::~AppManagedSharedStore() +{ +} + +int AppManagedSharedStore::init(Schema& schema) +{ + //TODO + return E_SUPPORT; +} + +int AppManagedSharedStore::insert(const std::vector& columns, Tuple& record) +{ + return E_PRIVIL; +} + +int AppManagedSharedStore::insert(const std::vector& columns, std::vector& records) +{ + return E_PRIVIL; +} + +int AppManagedSharedStore::remove(const std::string& selection) +{ + return E_PRIVIL; +} diff --git a/src/client/AppManagedSharedStore.h b/src/client/AppManagedSharedStore.h new file mode 100644 index 0000000..26168ba --- /dev/null +++ b/src/client/AppManagedSharedStore.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * 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 __CONTEXT_STORE_APP_MANAGED_SHARED_STORE_H__ +#define __CONTEXT_STORE_APP_MANAGED_SHARED_STORE_H__ + +#include +#include +#include +#include "AppManagedStore.h" +#include "Schema.h" + +namespace ctx { + + class AppManagedSharedStore : public AppManagedStore { + public: + AppManagedSharedStore(ServiceProxy* proxy); + ~AppManagedSharedStore(); + + int init(Schema& schema); + + int insert(const std::vector& columns, Tuple& record); + int insert(const std::vector& columns, std::vector& records); + int remove(const std::string& selection); + }; + +} + +#endif /* __CONTEXT_STORE_APP_MANAGED_SHARED_STORE_H__ */ diff --git a/src/client/AppManagedStore.cpp b/src/client/AppManagedStore.cpp new file mode 100644 index 0000000..3ba01fd --- /dev/null +++ b/src/client/AppManagedStore.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * 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 "AppManagedStore.h" + +using namespace ctx; + +AppManagedStore::AppManagedStore(ServiceProxy* proxy) : + __proxy(proxy) +{ +} + +AppManagedStore::~AppManagedStore() +{ +} + +int AppManagedStore::retrieve(const ContextStoreSearchQuery& query, std::vector& result) +{ + // TODO + return E_SUPPORT; +} diff --git a/src/client/AppManagedStore.h b/src/client/AppManagedStore.h new file mode 100644 index 0000000..6fd1035 --- /dev/null +++ b/src/client/AppManagedStore.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * 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 __CONTEXT_STORE_APP_MANAGED_STORE_H__ +#define __CONTEXT_STORE_APP_MANAGED_STORE_H__ + +#include +#include +#include +#include "Schema.h" + +namespace ctx { + + class AppManagedStore : public ContextStore { + public: + AppManagedStore(ServiceProxy* proxy); + virtual ~AppManagedStore(); + + int retrieve(const ContextStoreSearchQuery& query, std::vector& result); + + private: + ServiceProxy* __proxy; + }; + +} + +#endif /* __CONTEXT_STORE_APP_MANAGED_STORE_H__ */ diff --git a/src/client/ContextStore.cpp b/src/client/ContextStore.cpp index 051a48d..47eca13 100644 --- a/src/client/ContextStore.cpp +++ b/src/client/ContextStore.cpp @@ -15,25 +15,34 @@ */ #include -#include #include using namespace ctx; -/* TODO: Remove this test code */ -EXPORT_API int context_store_test() +ContextStore::ContextStore() { - // ServiceProxy object can be maintained as a static object. - ServiceProxy proxy(CTX_CONTEXT_STORE); +} - GVariant* output = NULL; +ContextStore::~ContextStore() +{ +} - int err = proxy.call("test", g_variant_new("(i)", 100), &output); +int ContextStore::insert(const std::vector& columns, Tuple& record) +{ + return E_SUPPORT; +} - _I(YELLOW("Return: %d (%s)"), err, CTX_ERROR_STR(err)); +int ContextStore::insert(const std::vector& columns, std::vector& records) +{ + return E_SUPPORT; +} - if (output) - g_variant_unref(output); +int ContextStore::retrieve(const ContextStoreSearchQuery& query, std::vector& result) +{ + return E_SUPPORT; +} - return err; +int ContextStore::remove(const std::string& selection) +{ + return E_SUPPORT; } diff --git a/src/client/ContextStoreManager.cpp b/src/client/ContextStoreManager.cpp new file mode 100644 index 0000000..692c582 --- /dev/null +++ b/src/client/ContextStoreManager.cpp @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * 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 +#include +#include +#include +#include +#include "SchemaConf.h" +#include "AppManagedLocalStore.h" +#include "AppManagedSharedStore.h" +#include "PlatformManagedStore.h" + +using namespace ctx; + +static SchemaConf __schemaConf; + +static ServiceProxy* __getServiceProxy() +{ + static ServiceProxy proxy(CTX_CONTEXT_STORE); + return &proxy; +} + +template +static ContextStore* __createStore(Schema& schema, int* error) +{ + StoreType* store = new(std::nothrow) StoreType(__getServiceProxy()); + + if (!store) { + *error = E_NO_MEM; + _E("Memory allocation failed"); + return NULL; + } + + *error = store->init(schema); + + if (*error != E_NONE) { + delete store; + return NULL; + } + + return store; +} + +ContextStoreManager::ContextStoreManager() +{ +} + +ContextStoreManager::~ContextStoreManager() +{ +} + +int ContextStoreManager::getStore(const std::string& uri, ContextStore** store) +{ + IF_FAIL_RETURN(store, E_PARAM); + IF_FAIL_RETURN(__schemaConf.init(), E_FAILED); + + Schema& schema = __schemaConf.getSchema(uri); + + int error = E_NONE; + ContextStore* _store = NULL; + + _store = __createStore(schema, &error); + + if (error == E_PARAM) + _store = __createStore(schema, &error); + + if (error == E_PARAM) + _store = __createStore(schema, &error); + + IF_FAIL_RETURN(_store, error); + + *store = _store; + return E_NONE; +} + +int ContextStoreManager::removeStore(const std::string& uri) +{ + int error = AppManagedLocalStore::destroy(uri, __getServiceProxy()); + + if (error == E_PARAM) + error = PlatformManagedStore::destroy(uri, __getServiceProxy()); + + return error; +} diff --git a/src/client/ContextStoreSearchQuery.cpp b/src/client/ContextStoreSearchQuery.cpp new file mode 100644 index 0000000..995f92d --- /dev/null +++ b/src/client/ContextStoreSearchQuery.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * 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 +#include + +using namespace ctx; + +ContextStoreSearchQuery::ContextStoreSearchQuery() : + __limit(0) +{ +} + +ContextStoreSearchQuery::ContextStoreSearchQuery(const std::string& projection, + const std::string& selection, const std::string& sortOrder, + unsigned int limit) : + __limit(0) +{ +} + +ContextStoreSearchQuery::~ContextStoreSearchQuery() +{ +} + +ContextStoreSearchQuery& ContextStoreSearchQuery::setProjection(const std::string& projection) +{ + __projection = projection; + return *this; +} + +ContextStoreSearchQuery& ContextStoreSearchQuery::setSelection(const std::string& selection) +{ + __selection = selection; + return *this; +} + +ContextStoreSearchQuery& ContextStoreSearchQuery::setSortOrder(const std::string& sortOrder) +{ + __sortOrder = sortOrder; + return *this; +} + +ContextStoreSearchQuery& ContextStoreSearchQuery::setLimit(unsigned int limit) +{ + __limit = limit; + return *this; +} + +bool ContextStoreSearchQuery::valid() +{ + // TODO + return true; +} diff --git a/src/client/PlatformManagedStore.cpp b/src/client/PlatformManagedStore.cpp new file mode 100644 index 0000000..bf856c8 --- /dev/null +++ b/src/client/PlatformManagedStore.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * 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 "PlatformManagedStore.h" + +using namespace ctx; + +PlatformManagedStore::PlatformManagedStore(ServiceProxy* proxy) : + __proxy(proxy) +{ +} + +PlatformManagedStore::~PlatformManagedStore() +{ +} + +int PlatformManagedStore::init(Schema& schema) +{ + // TODO + return E_SUPPORT; +} + +int PlatformManagedStore::insert(const std::vector& columns, Tuple& record) +{ + // TODO + return E_SUPPORT; +} + +int PlatformManagedStore::insert(const std::vector& columns, std::vector& records) +{ + // TODO + return E_SUPPORT; +} + +int PlatformManagedStore::retrieve(const ContextStoreSearchQuery& query, std::vector& result) +{ + // TODO + return E_SUPPORT; +} + +int PlatformManagedStore::remove(const std::string& selection) +{ + // TODO + return E_SUPPORT; +} + +int PlatformManagedStore::destroy(const std::string& uri, ServiceProxy* proxy) +{ + // TODO + return E_NONE; +} diff --git a/src/client/PlatformManagedStore.h b/src/client/PlatformManagedStore.h new file mode 100644 index 0000000..990f951 --- /dev/null +++ b/src/client/PlatformManagedStore.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * 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 __CONTEXT_STORE_PLATFORM_MANAGED_STORE_H__ +#define __CONTEXT_STORE_PLATFORM_MANAGED_STORE_H__ + +#include +#include +#include +#include "Schema.h" + +namespace ctx { + + class PlatformManagedStore : public ContextStore { + public: + PlatformManagedStore(ServiceProxy* proxy); + ~PlatformManagedStore(); + + int init(Schema& schema); + + int insert(const std::vector& columns, Tuple& record); + int insert(const std::vector& columns, std::vector& records); + int retrieve(const ContextStoreSearchQuery& query, std::vector& result); + int remove(const std::string& selection); + + static int destroy(const std::string& uri, ServiceProxy* proxy); + + private: + ServiceProxy* __proxy; + }; + +} + +#endif /* __CONTEXT_STORE_PLATFORM_MANAGED_STORE_H__ */ diff --git a/src/client/Schema.cpp b/src/client/Schema.cpp new file mode 100644 index 0000000..cfbe505 --- /dev/null +++ b/src/client/Schema.cpp @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * 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 "Schema.h" + +using namespace ctx; + +Schema::Schema() +{ +} + +Schema::~Schema() +{ +} diff --git a/src/client/Schema.h b/src/client/Schema.h new file mode 100644 index 0000000..1e94e3b --- /dev/null +++ b/src/client/Schema.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * 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 __CONTEXT_STORE_SCHEMA_H__ +#define __CONTEXT_STORE_SCHEMA_H__ + +#include +#include + +namespace ctx { + + class Schema { + public: + ~Schema(); + + private: + Schema(); + + friend class SchemaConf; + }; + +} + +#endif /* __CONTEXT_STORE_SCHEMA_H__ */ diff --git a/src/client/SchemaConf.cpp b/src/client/SchemaConf.cpp new file mode 100644 index 0000000..bccebdf --- /dev/null +++ b/src/client/SchemaConf.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * 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 "SchemaConf.h" + +using namespace ctx; + +SchemaConf::SchemaConf() +{ +} + +SchemaConf::~SchemaConf() +{ +} + +bool SchemaConf::init() +{ + return true; +} + +Schema& SchemaConf::getSchema(const std::string& uri) +{ + static Schema dummy; + return dummy; +} diff --git a/src/client/SchemaConf.h b/src/client/SchemaConf.h new file mode 100644 index 0000000..3bb0674 --- /dev/null +++ b/src/client/SchemaConf.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * 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 __CONTEXT_STORE_SCHEMA_CONF_H__ +#define __CONTEXT_STORE_SCHEMA_CONF_H__ + +#include +#include +#include "Schema.h" + +namespace ctx { + + class SchemaConf { + public: + SchemaConf(); + ~SchemaConf(); + + bool init(); + + Schema& getSchema(const std::string& uri); + }; + +} + +#endif /* __CONTEXT_STORE_SCHEMA_CONF_H__ */ diff --git a/src/shared/ContextStoreTypesPrivate.h b/src/shared/ContextStoreTypesPrivate.h index abcbbe0..5322d5f 100644 --- a/src/shared/ContextStoreTypesPrivate.h +++ b/src/shared/ContextStoreTypesPrivate.h @@ -19,6 +19,7 @@ #include #include +#include #define CTX_CONTEXT_STORE "ContextStore" #define CTX_CONTEXT_STORE_SPEC \ -- 2.7.4 From 7a9009659080dac70bfa21772b01923f883e2016 Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Wed, 8 Mar 2017 17:15:37 +0900 Subject: [PATCH 10/16] Remove API features managing databases in the application directories Not supported in Tizen 4.0. Change-Id: Icf003353317c9da1f8c4a14c14a4165ba5447c66 Signed-off-by: Mu-Woong Lee --- include/ContextStore.h | 2 +- packaging/context-store.spec | 3 +- src/client-dummy/ContextStore.cpp | 2 +- src/client/AppManagedLocalStore.cpp | 58 ------------------------------------ src/client/AppManagedLocalStore.h | 44 --------------------------- src/client/AppManagedSharedStore.cpp | 49 ------------------------------ src/client/AppManagedSharedStore.h | 42 -------------------------- src/client/AppManagedStore.cpp | 34 --------------------- src/client/AppManagedStore.h | 40 ------------------------- src/client/ContextStore.cpp | 2 +- src/client/ContextStoreManager.cpp | 35 ++++++++-------------- src/client/PlatformManagedStore.cpp | 4 +-- src/client/PlatformManagedStore.h | 5 ++-- src/client/Schema.cpp | 27 ----------------- src/client/Schema.h | 37 ----------------------- src/client/SchemaConf.cpp | 38 ----------------------- src/client/SchemaConf.h | 38 ----------------------- 17 files changed, 21 insertions(+), 439 deletions(-) delete mode 100644 src/client/AppManagedLocalStore.cpp delete mode 100644 src/client/AppManagedLocalStore.h delete mode 100644 src/client/AppManagedSharedStore.cpp delete mode 100644 src/client/AppManagedSharedStore.h delete mode 100644 src/client/AppManagedStore.cpp delete mode 100644 src/client/AppManagedStore.h delete mode 100644 src/client/Schema.cpp delete mode 100644 src/client/Schema.h delete mode 100644 src/client/SchemaConf.cpp delete mode 100644 src/client/SchemaConf.h diff --git a/include/ContextStore.h b/include/ContextStore.h index cfe97d1..bd1222d 100644 --- a/include/ContextStore.h +++ b/include/ContextStore.h @@ -28,7 +28,7 @@ namespace ctx { public: virtual ~ContextStore(); - virtual int insert(const std::vector& columns, Tuple& record); + virtual int insert(const std::vector& columns, Tuple* record); virtual int insert(const std::vector& columns, std::vector& records); virtual int retrieve(const ContextStoreSearchQuery& query, std::vector& result); virtual int remove(const std::string& selection); diff --git a/packaging/context-store.spec b/packaging/context-store.spec index 235067e..573a430 100644 --- a/packaging/context-store.spec +++ b/packaging/context-store.spec @@ -9,10 +9,9 @@ Source0: %{name}-%{version}.tar.gz BuildRequires: cmake BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(gio-2.0) -BuildRequires: pkgconfig(sqlite3) +BuildRequires: pkgconfig(libxml-2.0) BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(capi-base-common) -BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(context-common-server) BuildRequires: pkgconfig(context-common-client) Provides: %{name}-profile_tv = %{version}-%{release} diff --git a/src/client-dummy/ContextStore.cpp b/src/client-dummy/ContextStore.cpp index 47eca13..dd2b1d2 100644 --- a/src/client-dummy/ContextStore.cpp +++ b/src/client-dummy/ContextStore.cpp @@ -27,7 +27,7 @@ ContextStore::~ContextStore() { } -int ContextStore::insert(const std::vector& columns, Tuple& record) +int ContextStore::insert(const std::vector& columns, Tuple* record) { return E_SUPPORT; } diff --git a/src/client/AppManagedLocalStore.cpp b/src/client/AppManagedLocalStore.cpp deleted file mode 100644 index 9480c4f..0000000 --- a/src/client/AppManagedLocalStore.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. - * - * 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 "AppManagedLocalStore.h" - -using namespace ctx; - -AppManagedLocalStore::AppManagedLocalStore(ServiceProxy* proxy) : - AppManagedStore(proxy) -{ -} - -AppManagedLocalStore::~AppManagedLocalStore() -{ -} - -int AppManagedLocalStore::init(Schema& schema) -{ - //TODO - return E_SUPPORT; -} - -int AppManagedLocalStore::insert(const std::vector& columns, Tuple& record) -{ - //TODO - return E_SUPPORT; -} - -int AppManagedLocalStore::insert(const std::vector& columns, std::vector& records) -{ - //TODO - return E_SUPPORT; -} - -int AppManagedLocalStore::remove(const std::string& selection) -{ - //TODO - return E_SUPPORT; -} - -int AppManagedLocalStore::destroy(const std::string& uri, ServiceProxy* proxy) -{ - //TODO - return E_NONE; -} diff --git a/src/client/AppManagedLocalStore.h b/src/client/AppManagedLocalStore.h deleted file mode 100644 index 8ae4cc1..0000000 --- a/src/client/AppManagedLocalStore.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. - * - * 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 __CONTEXT_STORE_APP_MANAGED_LOCAL_STORE_H__ -#define __CONTEXT_STORE_APP_MANAGED_LOCAL_STORE_H__ - -#include -#include -#include -#include "AppManagedStore.h" -#include "Schema.h" - -namespace ctx { - - class AppManagedLocalStore : public AppManagedStore { - public: - AppManagedLocalStore(ServiceProxy* proxy); - ~AppManagedLocalStore(); - - int init(Schema& schema); - - int insert(const std::vector& columns, Tuple& record); - int insert(const std::vector& columns, std::vector& records); - int remove(const std::string& selection); - - static int destroy(const std::string& uri, ServiceProxy* proxy); - }; - -} - -#endif /* __CONTEXT_STORE_APP_MANAGED_LOCAL_STORE_H__ */ diff --git a/src/client/AppManagedSharedStore.cpp b/src/client/AppManagedSharedStore.cpp deleted file mode 100644 index 0943d6b..0000000 --- a/src/client/AppManagedSharedStore.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. - * - * 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 "AppManagedSharedStore.h" - -using namespace ctx; - -AppManagedSharedStore::AppManagedSharedStore(ServiceProxy* proxy) : - AppManagedStore(proxy) -{ -} - -AppManagedSharedStore::~AppManagedSharedStore() -{ -} - -int AppManagedSharedStore::init(Schema& schema) -{ - //TODO - return E_SUPPORT; -} - -int AppManagedSharedStore::insert(const std::vector& columns, Tuple& record) -{ - return E_PRIVIL; -} - -int AppManagedSharedStore::insert(const std::vector& columns, std::vector& records) -{ - return E_PRIVIL; -} - -int AppManagedSharedStore::remove(const std::string& selection) -{ - return E_PRIVIL; -} diff --git a/src/client/AppManagedSharedStore.h b/src/client/AppManagedSharedStore.h deleted file mode 100644 index 26168ba..0000000 --- a/src/client/AppManagedSharedStore.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. - * - * 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 __CONTEXT_STORE_APP_MANAGED_SHARED_STORE_H__ -#define __CONTEXT_STORE_APP_MANAGED_SHARED_STORE_H__ - -#include -#include -#include -#include "AppManagedStore.h" -#include "Schema.h" - -namespace ctx { - - class AppManagedSharedStore : public AppManagedStore { - public: - AppManagedSharedStore(ServiceProxy* proxy); - ~AppManagedSharedStore(); - - int init(Schema& schema); - - int insert(const std::vector& columns, Tuple& record); - int insert(const std::vector& columns, std::vector& records); - int remove(const std::string& selection); - }; - -} - -#endif /* __CONTEXT_STORE_APP_MANAGED_SHARED_STORE_H__ */ diff --git a/src/client/AppManagedStore.cpp b/src/client/AppManagedStore.cpp deleted file mode 100644 index 3ba01fd..0000000 --- a/src/client/AppManagedStore.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. - * - * 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 "AppManagedStore.h" - -using namespace ctx; - -AppManagedStore::AppManagedStore(ServiceProxy* proxy) : - __proxy(proxy) -{ -} - -AppManagedStore::~AppManagedStore() -{ -} - -int AppManagedStore::retrieve(const ContextStoreSearchQuery& query, std::vector& result) -{ - // TODO - return E_SUPPORT; -} diff --git a/src/client/AppManagedStore.h b/src/client/AppManagedStore.h deleted file mode 100644 index 6fd1035..0000000 --- a/src/client/AppManagedStore.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. - * - * 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 __CONTEXT_STORE_APP_MANAGED_STORE_H__ -#define __CONTEXT_STORE_APP_MANAGED_STORE_H__ - -#include -#include -#include -#include "Schema.h" - -namespace ctx { - - class AppManagedStore : public ContextStore { - public: - AppManagedStore(ServiceProxy* proxy); - virtual ~AppManagedStore(); - - int retrieve(const ContextStoreSearchQuery& query, std::vector& result); - - private: - ServiceProxy* __proxy; - }; - -} - -#endif /* __CONTEXT_STORE_APP_MANAGED_STORE_H__ */ diff --git a/src/client/ContextStore.cpp b/src/client/ContextStore.cpp index 47eca13..dd2b1d2 100644 --- a/src/client/ContextStore.cpp +++ b/src/client/ContextStore.cpp @@ -27,7 +27,7 @@ ContextStore::~ContextStore() { } -int ContextStore::insert(const std::vector& columns, Tuple& record) +int ContextStore::insert(const std::vector& columns, Tuple* record) { return E_SUPPORT; } diff --git a/src/client/ContextStoreManager.cpp b/src/client/ContextStoreManager.cpp index 692c582..69679f4 100644 --- a/src/client/ContextStoreManager.cpp +++ b/src/client/ContextStoreManager.cpp @@ -19,15 +19,10 @@ #include #include #include -#include "SchemaConf.h" -#include "AppManagedLocalStore.h" -#include "AppManagedSharedStore.h" #include "PlatformManagedStore.h" using namespace ctx; -static SchemaConf __schemaConf; - static ServiceProxy* __getServiceProxy() { static ServiceProxy proxy(CTX_CONTEXT_STORE); @@ -35,19 +30,20 @@ static ServiceProxy* __getServiceProxy() } template -static ContextStore* __createStore(Schema& schema, int* error) +static ContextStore* __createStore(const std::string& uri, int* error) { StoreType* store = new(std::nothrow) StoreType(__getServiceProxy()); if (!store) { *error = E_NO_MEM; - _E("Memory allocation failed"); + _E("%s", CTX_ERROR_STR(*error)); return NULL; } - *error = store->init(schema); + *error = store->init(uri); if (*error != E_NONE) { + _E("%s", CTX_ERROR_STR(*error)); delete store; return NULL; } @@ -66,21 +62,12 @@ ContextStoreManager::~ContextStoreManager() int ContextStoreManager::getStore(const std::string& uri, ContextStore** store) { IF_FAIL_RETURN(store, E_PARAM); - IF_FAIL_RETURN(__schemaConf.init(), E_FAILED); - - Schema& schema = __schemaConf.getSchema(uri); + _D("Getting the store %s", uri.c_str()); int error = E_NONE; ContextStore* _store = NULL; - _store = __createStore(schema, &error); - - if (error == E_PARAM) - _store = __createStore(schema, &error); - - if (error == E_PARAM) - _store = __createStore(schema, &error); - + _store = __createStore(uri, &error); IF_FAIL_RETURN(_store, error); *store = _store; @@ -89,10 +76,14 @@ int ContextStoreManager::getStore(const std::string& uri, ContextStore** store) int ContextStoreManager::removeStore(const std::string& uri) { - int error = AppManagedLocalStore::destroy(uri, __getServiceProxy()); + _D("Dropping the store %s", uri.c_str()); + + int error = E_NONE; + + error = PlatformManagedStore::destroy(uri, __getServiceProxy()); - if (error == E_PARAM) - error = PlatformManagedStore::destroy(uri, __getServiceProxy()); + if (error != E_NONE) + _E("%s", CTX_ERROR_STR(error)); return error; } diff --git a/src/client/PlatformManagedStore.cpp b/src/client/PlatformManagedStore.cpp index bf856c8..575d29e 100644 --- a/src/client/PlatformManagedStore.cpp +++ b/src/client/PlatformManagedStore.cpp @@ -27,13 +27,13 @@ PlatformManagedStore::~PlatformManagedStore() { } -int PlatformManagedStore::init(Schema& schema) +int PlatformManagedStore::init(const std::string& uri) { // TODO return E_SUPPORT; } -int PlatformManagedStore::insert(const std::vector& columns, Tuple& record) +int PlatformManagedStore::insert(const std::vector& columns, Tuple* record) { // TODO return E_SUPPORT; diff --git a/src/client/PlatformManagedStore.h b/src/client/PlatformManagedStore.h index 990f951..fbc7bcd 100644 --- a/src/client/PlatformManagedStore.h +++ b/src/client/PlatformManagedStore.h @@ -20,7 +20,6 @@ #include #include #include -#include "Schema.h" namespace ctx { @@ -29,9 +28,9 @@ namespace ctx { PlatformManagedStore(ServiceProxy* proxy); ~PlatformManagedStore(); - int init(Schema& schema); + int init(const std::string& uri); - int insert(const std::vector& columns, Tuple& record); + int insert(const std::vector& columns, Tuple* record); int insert(const std::vector& columns, std::vector& records); int retrieve(const ContextStoreSearchQuery& query, std::vector& result); int remove(const std::string& selection); diff --git a/src/client/Schema.cpp b/src/client/Schema.cpp deleted file mode 100644 index cfbe505..0000000 --- a/src/client/Schema.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. - * - * 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 "Schema.h" - -using namespace ctx; - -Schema::Schema() -{ -} - -Schema::~Schema() -{ -} diff --git a/src/client/Schema.h b/src/client/Schema.h deleted file mode 100644 index 1e94e3b..0000000 --- a/src/client/Schema.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. - * - * 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 __CONTEXT_STORE_SCHEMA_H__ -#define __CONTEXT_STORE_SCHEMA_H__ - -#include -#include - -namespace ctx { - - class Schema { - public: - ~Schema(); - - private: - Schema(); - - friend class SchemaConf; - }; - -} - -#endif /* __CONTEXT_STORE_SCHEMA_H__ */ diff --git a/src/client/SchemaConf.cpp b/src/client/SchemaConf.cpp deleted file mode 100644 index bccebdf..0000000 --- a/src/client/SchemaConf.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. - * - * 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 "SchemaConf.h" - -using namespace ctx; - -SchemaConf::SchemaConf() -{ -} - -SchemaConf::~SchemaConf() -{ -} - -bool SchemaConf::init() -{ - return true; -} - -Schema& SchemaConf::getSchema(const std::string& uri) -{ - static Schema dummy; - return dummy; -} diff --git a/src/client/SchemaConf.h b/src/client/SchemaConf.h deleted file mode 100644 index 3bb0674..0000000 --- a/src/client/SchemaConf.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. - * - * 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 __CONTEXT_STORE_SCHEMA_CONF_H__ -#define __CONTEXT_STORE_SCHEMA_CONF_H__ - -#include -#include -#include "Schema.h" - -namespace ctx { - - class SchemaConf { - public: - SchemaConf(); - ~SchemaConf(); - - bool init(); - - Schema& getSchema(const std::string& uri); - }; - -} - -#endif /* __CONTEXT_STORE_SCHEMA_CONF_H__ */ -- 2.7.4 From ec7cc34ddb4cf5265761b4d1bdc66f4d1b7d628f Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Wed, 8 Mar 2017 21:39:12 +0900 Subject: [PATCH 11/16] Implement APIs for platform-managed stores Change-Id: Ifa8e2f3fd0fab6f9f807e39696932aea73467d15 Signed-off-by: Mu-Woong Lee --- include/ContextStore.h | 4 +-- include/ContextStoreManager.h | 1 - include/ContextStoreSearchQuery.h | 7 +++- src/client-dummy/ContextStore.cpp | 4 +-- src/client-dummy/ContextStoreManager.cpp | 5 --- src/client-dummy/ContextStoreSearchQuery.cpp | 22 +++++++++++- src/client/ContextStore.cpp | 4 +-- src/client/ContextStoreManager.cpp | 23 ++---------- src/client/ContextStoreSearchQuery.cpp | 22 +++++++++++- src/client/PlatformManagedStore.cpp | 53 ++++++++++++++++++---------- src/client/PlatformManagedStore.h | 9 ++--- src/shared/ContextStoreTypesPrivate.h | 30 ++++++++++++++-- 12 files changed, 124 insertions(+), 60 deletions(-) diff --git a/include/ContextStore.h b/include/ContextStore.h index bd1222d..214c988 100644 --- a/include/ContextStore.h +++ b/include/ContextStore.h @@ -28,8 +28,8 @@ namespace ctx { public: virtual ~ContextStore(); - virtual int insert(const std::vector& columns, Tuple* record); - virtual int insert(const std::vector& columns, std::vector& records); + virtual int insert(const std::string& columns, Tuple* record); + virtual int insert(const std::string& columns, std::vector& records); virtual int retrieve(const ContextStoreSearchQuery& query, std::vector& result); virtual int remove(const std::string& selection); diff --git a/include/ContextStoreManager.h b/include/ContextStoreManager.h index 4fbdcdc..60f2a3e 100644 --- a/include/ContextStoreManager.h +++ b/include/ContextStoreManager.h @@ -29,7 +29,6 @@ namespace ctx { ~ContextStoreManager(); int getStore(const std::string& uri, ContextStore** contextStore); - int removeStore(const std::string& uri); }; } diff --git a/include/ContextStoreSearchQuery.h b/include/ContextStoreSearchQuery.h index 2c0d187..c279676 100644 --- a/include/ContextStoreSearchQuery.h +++ b/include/ContextStoreSearchQuery.h @@ -38,7 +38,12 @@ namespace ctx { ContextStoreSearchQuery& setSortOrder(const std::string& sortOrder); ContextStoreSearchQuery& setLimit(unsigned int limit); - bool valid(); + const std::string& getProjection() const; + const std::string& getSelection() const; + const std::string& getSortOrder() const; + unsigned int getLimit() const; + + bool valid() const; private: std::string __projection; diff --git a/src/client-dummy/ContextStore.cpp b/src/client-dummy/ContextStore.cpp index dd2b1d2..3ac2af0 100644 --- a/src/client-dummy/ContextStore.cpp +++ b/src/client-dummy/ContextStore.cpp @@ -27,12 +27,12 @@ ContextStore::~ContextStore() { } -int ContextStore::insert(const std::vector& columns, Tuple* record) +int ContextStore::insert(const std::string& columns, Tuple* record) { return E_SUPPORT; } -int ContextStore::insert(const std::vector& columns, std::vector& records) +int ContextStore::insert(const std::string& columns, std::vector& records) { return E_SUPPORT; } diff --git a/src/client-dummy/ContextStoreManager.cpp b/src/client-dummy/ContextStoreManager.cpp index f19a6dc..9178735 100644 --- a/src/client-dummy/ContextStoreManager.cpp +++ b/src/client-dummy/ContextStoreManager.cpp @@ -31,8 +31,3 @@ int ContextStoreManager::getStore(const std::string& uri, ContextStore** store) { return E_SUPPORT; } - -int ContextStoreManager::removeStore(const std::string& uri) -{ - return E_SUPPORT; -} diff --git a/src/client-dummy/ContextStoreSearchQuery.cpp b/src/client-dummy/ContextStoreSearchQuery.cpp index 25f60d4..bda66fe 100644 --- a/src/client-dummy/ContextStoreSearchQuery.cpp +++ b/src/client-dummy/ContextStoreSearchQuery.cpp @@ -59,7 +59,27 @@ ContextStoreSearchQuery& ContextStoreSearchQuery::setLimit(unsigned int limit) return *this; } -bool ContextStoreSearchQuery::valid() +const std::string& ContextStoreSearchQuery::getProjection() const +{ + return __projection; +} + +const std::string& ContextStoreSearchQuery::getSelection() const +{ + return __selection; +} + +const std::string& ContextStoreSearchQuery::getSortOrder() const +{ + return __sortOrder; +} + +unsigned int ContextStoreSearchQuery::getLimit() const +{ + return __limit; +} + +bool ContextStoreSearchQuery::valid() const { return false; } diff --git a/src/client/ContextStore.cpp b/src/client/ContextStore.cpp index dd2b1d2..3ac2af0 100644 --- a/src/client/ContextStore.cpp +++ b/src/client/ContextStore.cpp @@ -27,12 +27,12 @@ ContextStore::~ContextStore() { } -int ContextStore::insert(const std::vector& columns, Tuple* record) +int ContextStore::insert(const std::string& columns, Tuple* record) { return E_SUPPORT; } -int ContextStore::insert(const std::vector& columns, std::vector& records) +int ContextStore::insert(const std::string& columns, std::vector& records) { return E_SUPPORT; } diff --git a/src/client/ContextStoreManager.cpp b/src/client/ContextStoreManager.cpp index 69679f4..9dcca7c 100644 --- a/src/client/ContextStoreManager.cpp +++ b/src/client/ContextStoreManager.cpp @@ -15,8 +15,6 @@ */ #include -#include -#include #include #include #include "PlatformManagedStore.h" @@ -29,10 +27,9 @@ static ServiceProxy* __getServiceProxy() return &proxy; } -template -static ContextStore* __createStore(const std::string& uri, int* error) +static ContextStore* __createPlatformManagedStore(const std::string& uri, int* error) { - StoreType* store = new(std::nothrow) StoreType(__getServiceProxy()); + PlatformManagedStore* store = new(std::nothrow) PlatformManagedStore(__getServiceProxy()); if (!store) { *error = E_NO_MEM; @@ -67,23 +64,9 @@ int ContextStoreManager::getStore(const std::string& uri, ContextStore** store) int error = E_NONE; ContextStore* _store = NULL; - _store = __createStore(uri, &error); + _store = __createPlatformManagedStore(uri, &error); IF_FAIL_RETURN(_store, error); *store = _store; return E_NONE; } - -int ContextStoreManager::removeStore(const std::string& uri) -{ - _D("Dropping the store %s", uri.c_str()); - - int error = E_NONE; - - error = PlatformManagedStore::destroy(uri, __getServiceProxy()); - - if (error != E_NONE) - _E("%s", CTX_ERROR_STR(error)); - - return error; -} diff --git a/src/client/ContextStoreSearchQuery.cpp b/src/client/ContextStoreSearchQuery.cpp index 995f92d..d401725 100644 --- a/src/client/ContextStoreSearchQuery.cpp +++ b/src/client/ContextStoreSearchQuery.cpp @@ -59,7 +59,27 @@ ContextStoreSearchQuery& ContextStoreSearchQuery::setLimit(unsigned int limit) return *this; } -bool ContextStoreSearchQuery::valid() +const std::string& ContextStoreSearchQuery::getProjection() const +{ + return __projection; +} + +const std::string& ContextStoreSearchQuery::getSelection() const +{ + return __selection; +} + +const std::string& ContextStoreSearchQuery::getSortOrder() const +{ + return __sortOrder; +} + +unsigned int ContextStoreSearchQuery::getLimit() const +{ + return __limit; +} + +bool ContextStoreSearchQuery::valid() const { // TODO return true; diff --git a/src/client/PlatformManagedStore.cpp b/src/client/PlatformManagedStore.cpp index 575d29e..1c0c8f8 100644 --- a/src/client/PlatformManagedStore.cpp +++ b/src/client/PlatformManagedStore.cpp @@ -29,36 +29,53 @@ PlatformManagedStore::~PlatformManagedStore() int PlatformManagedStore::init(const std::string& uri) { - // TODO - return E_SUPPORT; + int error = __proxy->call(METHOD_GET_ACCESS, g_variant_new("(s)", uri.c_str())); + __uri = uri; + return error; } -int PlatformManagedStore::insert(const std::vector& columns, Tuple* record) +int PlatformManagedStore::insert(const std::string& columns, Tuple* record) { - // TODO - return E_SUPPORT; + if (columns.empty() || record == NULL) { + delete record; + return E_PARAM; + } + + GVariant* param = g_variant_new("(ssv)", __uri.c_str(), columns.c_str(), Tuple::toGVariant(record)); + return __proxy->call(METHOD_INSERT, param); } -int PlatformManagedStore::insert(const std::vector& columns, std::vector& records) +int PlatformManagedStore::insert(const std::string& columns, std::vector& records) { - // TODO - return E_SUPPORT; + if (columns.empty() || records.empty()) { + for (auto& tuple : records) { + delete tuple; + } + records.clear(); + return E_PARAM; + } + + GVariant* param = g_variant_new("(ssv)", __uri.c_str(), columns.c_str(), Tuple::toGVariant(records)); + return __proxy->call(METHOD_INSERT, param); } int PlatformManagedStore::retrieve(const ContextStoreSearchQuery& query, std::vector& result) { - // TODO - return E_SUPPORT; -} + IF_FAIL_RETURN(query.valid(), E_PARAM); -int PlatformManagedStore::remove(const std::string& selection) -{ - // TODO - return E_SUPPORT; + GVariant* param = g_variant_new("(ssssu)", __uri.c_str(), + query.getProjection().c_str(), query.getSelection().c_str(), + query.getSortOrder().c_str(), static_cast(query.getLimit())); + + GVariant* outParam = NULL; + int error = __proxy->call(METHOD_RETRIEVE, param, &outParam); + IF_FAIL_RETURN_TAG(error == E_NONE, error, _E, "%s", CTX_ERROR_STR(error)); + + result = Tuple::buildFrom(g_variant_get_child_value(outParam, IDX_RETRIEVE_RESULT)); + return E_NONE; } -int PlatformManagedStore::destroy(const std::string& uri, ServiceProxy* proxy) +int PlatformManagedStore::remove(const std::string& selection) { - // TODO - return E_NONE; + return __proxy->call(METHOD_REMOVE, g_variant_new("(ss)", __uri.c_str(), selection.c_str())); } diff --git a/src/client/PlatformManagedStore.h b/src/client/PlatformManagedStore.h index fbc7bcd..c5d0786 100644 --- a/src/client/PlatformManagedStore.h +++ b/src/client/PlatformManagedStore.h @@ -18,6 +18,8 @@ #define __CONTEXT_STORE_PLATFORM_MANAGED_STORE_H__ #include +#include +#include #include #include @@ -30,15 +32,14 @@ namespace ctx { int init(const std::string& uri); - int insert(const std::vector& columns, Tuple* record); - int insert(const std::vector& columns, std::vector& records); + int insert(const std::string& columns, Tuple* record); + int insert(const std::string& columns, std::vector& records); int retrieve(const ContextStoreSearchQuery& query, std::vector& result); int remove(const std::string& selection); - static int destroy(const std::string& uri, ServiceProxy* proxy); - private: ServiceProxy* __proxy; + std::string __uri; }; } diff --git a/src/shared/ContextStoreTypesPrivate.h b/src/shared/ContextStoreTypesPrivate.h index 5322d5f..e482308 100644 --- a/src/shared/ContextStoreTypesPrivate.h +++ b/src/shared/ContextStoreTypesPrivate.h @@ -23,9 +23,33 @@ #define CTX_CONTEXT_STORE "ContextStore" #define CTX_CONTEXT_STORE_SPEC \ - "" \ - " " \ - " " \ + "" \ + " " \ + " " \ + "" \ + "" \ + " " \ + " " \ + " " \ + "" \ + "" \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + "" \ + "" \ + " " \ + " " \ "" +#define METHOD_GET_ACCESS "GetAccess" +#define METHOD_INSERT "Insert" +#define METHOD_RETRIEVE "Retrieve" +#define METHOD_REMOVE "Remove" + +#define IDX_RETRIEVE_RESULT 0 + #endif -- 2.7.4 From 7a2782856a772c192430d1f56c6f4f62d7839ece Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Tue, 14 Mar 2017 20:38:58 +0900 Subject: [PATCH 12/16] Define shared constants Change-Id: I17cb3508e80e0699383add2a805923841eab620d Signed-off-by: Mu-Woong Lee --- src/shared/ContextStoreTypesPrivate.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/shared/ContextStoreTypesPrivate.h b/src/shared/ContextStoreTypesPrivate.h index e482308..786fec0 100644 --- a/src/shared/ContextStoreTypesPrivate.h +++ b/src/shared/ContextStoreTypesPrivate.h @@ -50,6 +50,16 @@ #define METHOD_RETRIEVE "Retrieve" #define METHOD_REMOVE "Remove" +#define IDX_URI 0 #define IDX_RETRIEVE_RESULT 0 +#define MAX_RETENTION 8760 // one year +#define MAX_LIMIT 100000 +#define PRIVILEGE_DELIM ";" + +#define BASE_PATH "context-store" + +#define COL_TIMESTAMP "__timestamp" +#define COL_OWNER_ID "__ownerId" + #endif -- 2.7.4 From e3d9d6af8b3122afab2dba7668f764afaffc9bc0 Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Tue, 14 Mar 2017 20:43:09 +0900 Subject: [PATCH 13/16] API: fix bugs of query construction & GVariant extraction Change-Id: Id47ea1dcddff38717f1aecc8acd8a2cb15bef7a7 Signed-off-by: Mu-Woong Lee --- src/client/ContextStoreSearchQuery.cpp | 5 ++++- src/client/PlatformManagedStore.cpp | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/client/ContextStoreSearchQuery.cpp b/src/client/ContextStoreSearchQuery.cpp index d401725..e1161b6 100644 --- a/src/client/ContextStoreSearchQuery.cpp +++ b/src/client/ContextStoreSearchQuery.cpp @@ -27,7 +27,10 @@ ContextStoreSearchQuery::ContextStoreSearchQuery() : ContextStoreSearchQuery::ContextStoreSearchQuery(const std::string& projection, const std::string& selection, const std::string& sortOrder, unsigned int limit) : - __limit(0) + __projection(projection), + __selection(selection), + __sortOrder(sortOrder), + __limit(limit) { } diff --git a/src/client/PlatformManagedStore.cpp b/src/client/PlatformManagedStore.cpp index 1c0c8f8..ed913af 100644 --- a/src/client/PlatformManagedStore.cpp +++ b/src/client/PlatformManagedStore.cpp @@ -71,7 +71,10 @@ int PlatformManagedStore::retrieve(const ContextStoreSearchQuery& query, std::ve int error = __proxy->call(METHOD_RETRIEVE, param, &outParam); IF_FAIL_RETURN_TAG(error == E_NONE, error, _E, "%s", CTX_ERROR_STR(error)); - result = Tuple::buildFrom(g_variant_get_child_value(outParam, IDX_RETRIEVE_RESULT)); + GVariant* vals = NULL; + g_variant_get(outParam, "(v)", &vals); + + result = Tuple::buildFrom(vals); return E_NONE; } -- 2.7.4 From 0a7cbcee315f5c24df8f4554352b4ff8d4ca098c Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Tue, 14 Mar 2017 20:44:26 +0900 Subject: [PATCH 14/16] Add a schema sample xml Change-Id: Ie233bd104e6538d91857ba4468eaeff6c4e2c7ad Signed-off-by: Mu-Woong Lee --- schema/sample.xml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 schema/sample.xml diff --git a/schema/sample.xml b/schema/sample.xml new file mode 100644 index 0000000..6e67c38 --- /dev/null +++ b/schema/sample.xml @@ -0,0 +1,11 @@ + + + + http://tizen.org/privilege/location + http://tizen.org/privilege/internal/service + + + + + + -- 2.7.4 From a4402485c82fbe50366d4d096b2619b192a313d3 Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Tue, 14 Mar 2017 20:47:08 +0900 Subject: [PATCH 15/16] Implement DatabaseManager in the server Change-Id: Ib88f7fd66583ce4632d52a003b169c9479d664b4 Signed-off-by: Mu-Woong Lee --- src/server/DatabaseManager.cpp | 111 +++++++++++++++++++++++++++++++++++++++++ src/server/DatabaseManager.h | 48 ++++++++++++++++++ 2 files changed, 159 insertions(+) create mode 100644 src/server/DatabaseManager.cpp create mode 100644 src/server/DatabaseManager.h diff --git a/src/server/DatabaseManager.cpp b/src/server/DatabaseManager.cpp new file mode 100644 index 0000000..bb5a3bb --- /dev/null +++ b/src/server/DatabaseManager.cpp @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * 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 +#include "DatabaseManager.h" + +using namespace ctx; + +Database* DatabaseManager::__systemDatabase = NULL; +Database* DatabaseManager::__userDatabase = NULL; + +DatabaseManager::DatabaseManager() +{ +} + +bool DatabaseManager::openSystem() +{ + IF_FAIL_RETURN(!isSystemReady(), true); + + __systemDatabase = new(std::nothrow) PlatformDatabase(BASE_PATH); + IF_FAIL_RETURN_TAG(__systemDatabase, false, _E, "%s", CTX_ERROR_STR(E_NO_MEM)); + + if (!__systemDatabase->open()) { + _E("DB open failed"); + delete __systemDatabase; + __systemDatabase = NULL; + return false; + } + + _I("System DB opened"); + return true; +} + +bool DatabaseManager::openUser(uid_t uid) +{ + if (isUserReady()) { + _W("Closing the current DB"); + closeUser(); + } + + __userDatabase = new(std::nothrow) PlatformDatabase(BASE_PATH, uid); + IF_FAIL_RETURN_TAG(__userDatabase, false, _E, "%s", CTX_ERROR_STR(E_NO_MEM)); + + if (!__userDatabase->open()) { + _E("DB open failed"); + delete __userDatabase; + __userDatabase = NULL; + return false; + } + + _I("User DB opened"); + return true; +} + +void DatabaseManager::closeSystem() +{ + if (!__systemDatabase) + return; + + __systemDatabase->close(); + _I("System DB closed"); + + delete __systemDatabase; + __systemDatabase = NULL; + +} + +void DatabaseManager::closeUser() +{ + if (!__userDatabase) + return; + + __userDatabase->close(); + _I("User DB closed"); + + delete __userDatabase; + __userDatabase = NULL; +} + +bool DatabaseManager::isSystemReady() +{ + return (__systemDatabase != NULL); +} + +bool DatabaseManager::isUserReady() +{ + return (__userDatabase != NULL); +} + +Database& DatabaseManager::getSystem() +{ + return *__systemDatabase; +} + +Database& DatabaseManager::getUser() +{ + return *__userDatabase; +} diff --git a/src/server/DatabaseManager.h b/src/server/DatabaseManager.h new file mode 100644 index 0000000..b274443 --- /dev/null +++ b/src/server/DatabaseManager.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * 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 __CONTEXT_STORE_DATABASE_MANAGER_H__ +#define __CONTEXT_STORE_DATABASE_MANAGER_H__ + +#include +#include + +namespace ctx { + + class DatabaseManager { + public: + static bool openSystem(); + static bool openUser(uid_t uid); + + static void closeSystem(); + static void closeUser(); + + static bool isSystemReady(); + static bool isUserReady(); + + static Database& getSystem(); + static Database& getUser(); + + private: + DatabaseManager(); + + static Database* __systemDatabase; + static Database* __userDatabase; + }; + +} + +#endif /* __CONTEXT_STORE_DATABASE_MANAGER_H__ */ -- 2.7.4 From 88dc1c784794d4854fae5a5b707beb15942e250d Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Tue, 14 Mar 2017 20:52:19 +0900 Subject: [PATCH 16/16] Implement SchemaLoader in the server Change-Id: I86e52eace38cdd0710e198712df1aa894bf68dd4 Signed-off-by: Mu-Woong Lee --- packaging/context-store.spec | 4 +- script/init.sql | 7 + src/server/SchemaLoader.cpp | 375 +++++++++++++++++++++++++++++++++++++++++++ src/server/SchemaLoader.h | 91 +++++++++++ 4 files changed, 476 insertions(+), 1 deletion(-) create mode 100644 script/init.sql create mode 100644 src/server/SchemaLoader.cpp create mode 100644 src/server/SchemaLoader.h diff --git a/packaging/context-store.spec b/packaging/context-store.spec index 573a430..5c4a488 100644 --- a/packaging/context-store.spec +++ b/packaging/context-store.spec @@ -61,7 +61,8 @@ make %{?_smp_mflags} %install %make_install - +mkdir -p %{buildroot}%{TZ_SYS_DATA}/%{name} +install -m 0644 script/init.sql %{buildroot}%{TZ_SYS_DATA}/%{name}/ %post /sbin/ldconfig @@ -89,6 +90,7 @@ popd %manifest packaging/%{name}.manifest %{_libdir}/lib%{name}-client-genuine.so* %{_libdir}/lib%{name}-server-genuine.so* +%{TZ_SYS_DATA}/%{name}/*.sql %files devel diff --git a/script/init.sql b/script/init.sql new file mode 100644 index 0000000..d0ec0c9 --- /dev/null +++ b/script/init.sql @@ -0,0 +1,7 @@ +CREATE TABLE IF NOT EXISTS ContextStoreSchema ( + "uri" TEXT PRIMARY KEY, + "retention" INTEGER NOT NULL DEFAULT 0, + "limit" INTEGER NOT NULL DEFAULT 0, + "readPrivileges" TEXT NOT NULL, + "writePrivileges" TEXT NOT NULL +); diff --git a/src/server/SchemaLoader.cpp b/src/server/SchemaLoader.cpp new file mode 100644 index 0000000..6185762 --- /dev/null +++ b/src/server/SchemaLoader.cpp @@ -0,0 +1,375 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * 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 +#include +#include +#include +#include +#include +#include "DatabaseManager.h" +#include "SchemaLoader.h" + +/* Schema XML example: + + + + + http://tizen.org/privilege/healthinfo + http://tizen.org/privilege/internal/service + + + + + + + */ + +#define URI_REGEX(CATEGORY) R"~(^http:\/\/[\w-]+(\.[\w-]+)*\/)~" CATEGORY R"~(\/[\w-]+(\.[\w-]+)*(\/[\w-]+(\.[\w-]+)*)*$)~" +#define COL_REGEX "^[A-Za-z]+\\w*$" + +#define CHK_NAME(NODE, NAME) (!xmlStrcmp(NODE->name, (const xmlChar*)(NAME))) + +using namespace ctx; + +static std::string __getXmlAttribute(xmlNode* node, const char* name) +{ + xmlChar* prop = xmlGetProp(node, reinterpret_cast(name)); + std::string out; + if (prop) { + out = reinterpret_cast(prop); + xmlFree(prop); + } + return out; +} + +static std::string __getXmlContent(xmlNode* node) +{ + xmlChar* content = xmlNodeGetContent(node); + _D("%s", content); + std::string out; + if (content) { + out = reinterpret_cast(content); + xmlFree(content); + } + return out; +} + +Schema::Schema() : + retention(0), + limit(0) +{ +} + +bool Schema::valid() +{ + if (retention > MAX_RETENTION || limit > MAX_LIMIT) + return false; + + if (retention == 0 && limit == 0) + return false; + + if (attributes.empty()) + return false; + + std::regex uriRegex(URI_REGEX("contextstore"), std::regex::optimize); + if (!std::regex_match(uri, uriRegex)) + return false; + + std::regex privilegeRegex(URI_REGEX("privilege"), std::regex::optimize); + for (auto& privil : readPrivileges) { + if (!std::regex_match(privil, privilegeRegex)) + return false; + } + + for (auto& privil : writePrivileges) { + if (!std::regex_match(privil, privilegeRegex)) + return false; + } + + std::regex columnNameRegex(COL_REGEX, std::regex::optimize); + for (auto& attr: attributes) { + if (!std::regex_match(attr.first, columnNameRegex)) + return false; + } + + return true; +} + +SchemaLoader::SchemaLoader() +{ +} + +SchemaLoader::~SchemaLoader() +{ +} + +bool SchemaLoader::load() +{ + bool result = true; + __getDatabase().beginTransaction(); + + if (!__createMetadataTables()) { + _E("Metadata table creation failed"); + result = false; + } + + try { + if (result && !__loadSchemaDir(__getSchemaDir())) { + _W("Schema loading failed"); + result = false; + } + } catch (std::regex_error& e) { + _E("%s", e.what()); + result = false; + } + + __getDatabase().endTransaction(); + return result; +} + +bool SchemaLoader::__createMetadataTables() +{ + std::string path = PathUtil::getSystemPath(TZ_SYS_DATA, BASE_PATH "/init.sql"); + IF_FAIL_RETURN(!path.empty(), false); + + std::ifstream inFile(path); + std::stringstream buffer; + buffer << inFile.rdbuf(); + + return __getDatabase().execute(buffer.str(), NULL); +} + +bool SchemaLoader::__loadSchemaDir(const std::string& dirPath) +{ + DIR* dir = NULL; + struct dirent entry; + struct dirent *result = NULL; + + dir = opendir(dirPath.c_str()); + IF_FAIL_RETURN_TAG(dir, false, _E, "Failed to open: %s", dirPath.c_str()); + + std::regex xmlFileRegex("^.*\\.(xml|XML)$", std::regex::optimize); + + while (true) { + if (readdir_r(dir, &entry, &result) != 0) + continue; + + if (result == NULL) + break; + + std::string filename = entry.d_name; + + if (!std::regex_match(filename, xmlFileRegex)) + continue; + + __parseSchemaFile(dirPath + "/" + filename); + } + + closedir(dir); + return true; +} + +void SchemaLoader::__parseSchemaFile(const std::string& filePath) +{ + _D("Parsing %s", filePath.c_str()); + + xmlDoc *doc = xmlReadFile(filePath.c_str(), NULL, 0); + IF_FAIL_VOID_TAG(doc, _W, "Could not parse %s", filePath.c_str()); + + xmlNode *node = xmlDocGetRootElement(doc); + + if (!node || !CHK_NAME(node, "ContextStore")) { + _W("Not a ContextStore schema XML"); + xmlFreeDoc(doc); + return; + } + + for (node = node->children; node != NULL; node = node->next) { + if (node->type != XML_ELEMENT_NODE) + continue; + + if (!CHK_NAME(node, "Schema")) { + _D("Skip '%s'", node->name); + continue; + } + + Schema schema; + if (__parseSchema(node, schema)) { + __insertMetadata(schema); + __createStoreTable(schema); + } + } + + xmlFreeDoc(doc); + return; +} + +bool SchemaLoader::__parseSchema(xmlNode* node, Schema& schema) +{ + std::string retention = __getXmlAttribute(node, "retention"); + std::string limit = __getXmlAttribute(node, "limit"); + schema.uri = __getXmlAttribute(node, "uri"); + + for (node = node->children; node != NULL; node = node->next) { + if (node->type != XML_ELEMENT_NODE) + continue; + + if (CHK_NAME(node, "Privilege")) + __parsePrivilege(node, schema); + else if (CHK_NAME(node, "Attribute")) + __parseAttribute(node, schema); + } + + if (!retention.empty()) + schema.retention = std::atoi(retention.c_str()); + + if (!limit.empty()) + schema.limit = std::atoi(limit.c_str()); + + return schema.valid(); +} + +void SchemaLoader::__parsePrivilege(xmlNode* node, Schema& schema) +{ + std::string access = __getXmlAttribute(node, "access"); + std::string privil = __getXmlContent(node); + + if (access == "Read") + schema.readPrivileges.push_back(privil); + else if (access == "Write") + schema.writePrivileges.push_back(privil); +} + +void SchemaLoader::__parseAttribute(xmlNode* node, Schema& schema) +{ + std::string name = __getXmlAttribute(node, "name"); + std::string type = __getXmlAttribute(node, "type"); + + IF_FAIL_VOID(!name.empty()); + + if (type == "Integer") + schema.attributes.push_back(std::make_pair(name, Schema::AttributeType::INTEGER)); + else if (type == "Real") + schema.attributes.push_back(std::make_pair(name, Schema::AttributeType::REAL)); + else if (type == "Text") + schema.attributes.push_back(std::make_pair(name, Schema::AttributeType::TEXT)); +} + +void SchemaLoader::__insertMetadata(Schema& schema) +{ + char* updateSql = NULL; + char* insertSql = NULL; + int length = 0; + + std::string readPrivil; + std::string writePrivil; + + for (auto& item : schema.readPrivileges) { + readPrivil.append(item); + readPrivil.append(PRIVILEGE_DELIM); + } + + for (auto& item : schema.writePrivileges) { + writePrivil.append(item); + writePrivil.append(PRIVILEGE_DELIM); + } + + length = asprintf(&updateSql, + "UPDATE ContextStoreSchema" + " SET uri='%s', retention=%u, \"limit\"=%u, readPrivileges='%s', writePrivileges='%s'" + " WHERE uri='%s'", + schema.uri.c_str(), schema.retention, schema.limit, readPrivil.c_str(), writePrivil.c_str(), + schema.uri.c_str()); + if (length <= 0) { + _E("Memory allocation failed"); + return; + } + + length = asprintf(&insertSql, + "INSERT OR IGNORE INTO ContextStoreSchema" + " (uri, retention, \"limit\", readPrivileges, writePrivileges)" + " VALUES ('%s', %u, %u, '%s', '%s')", + schema.uri.c_str(), schema.retention, schema.limit, readPrivil.c_str(), writePrivil.c_str()); + if (length <= 0) { + g_free(updateSql); + _E("Memory allocation failed"); + return; + } + + __getDatabase().execute(updateSql, NULL); + __getDatabase().execute(insertSql, NULL); + + g_free(updateSql); + g_free(insertSql); +} + +void SchemaLoader::__createStoreTable(Schema& schema) +{ + std::string attr = + COL_TIMESTAMP " DATETIME DEFAULT CURRENT_TIMESTAMP," + COL_OWNER_ID " TEXT NOT NULL DEFAULT ''"; + + for (auto& item : schema.attributes) { + attr = attr + "," + item.first; + switch (item.second) { + case Schema::AttributeType::INTEGER: + attr = attr + " INTEGER NOT NULL DEFAULT 0"; + break; + case Schema::AttributeType::REAL: + attr = attr + " REAL NOT NULL DEFAULT 0"; + break; + default: + attr = attr + " TEXT NOT NULL DEFAULT ''"; + break; + } + } + + std::string query = + "CREATE TABLE IF NOT EXISTS [" + schema.uri + "] (" + attr + ")"; + + __getDatabase().execute(query.c_str(), NULL); +} + + +SystemSchemaLoader::SystemSchemaLoader() +{ +} + +Database& SystemSchemaLoader::__getDatabase() +{ + return DatabaseManager::getSystem(); +} + +std::string SystemSchemaLoader::__getSchemaDir() +{ + return PathUtil::getSystemPath(TZ_SYS_DATA, BASE_PATH "/system"); +} + + +UserSchemaLoader::UserSchemaLoader() +{ +} + +Database& UserSchemaLoader::__getDatabase() +{ + return DatabaseManager::getUser(); +} + +std::string UserSchemaLoader::__getSchemaDir() +{ + return PathUtil::getSystemPath(TZ_SYS_DATA, BASE_PATH "/user"); +} diff --git a/src/server/SchemaLoader.h b/src/server/SchemaLoader.h new file mode 100644 index 0000000..4b08934 --- /dev/null +++ b/src/server/SchemaLoader.h @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * 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 __CONTEXT_STORE_SCHEMA_LOADER_H__ +#define __CONTEXT_STORE_SCHEMA_LOADER_H__ + +#include +#include +#include +#include +#include +#include + +namespace ctx { + + class Schema { + public: + enum class AttributeType { + UNDEFINED = 0, + INTEGER = 1, + REAL = 2, + TEXT = 3 + }; + + Schema(); + bool valid(); + + std::string uri; + unsigned int retention; + unsigned int limit; + std::vector readPrivileges; + std::vector writePrivileges; + std::vector> attributes; + }; + + class SchemaLoader { + public: + virtual ~SchemaLoader(); + + bool load(); + + private: + bool __createMetadataTables(); + bool __loadSchemaDir(const std::string& dirPath); + void __parseSchemaFile(const std::string& filePath); + bool __parseSchema(xmlNode* node, Schema& schema); + void __parsePrivilege(xmlNode* node, Schema& schema); + void __parseAttribute(xmlNode* node, Schema& schema); + void __insertMetadata(Schema& schema); + void __createStoreTable(Schema& schema); + + virtual std::string __getSchemaDir() = 0; + virtual Database& __getDatabase() = 0; + + protected: + SchemaLoader(); + }; + + class SystemSchemaLoader : public SchemaLoader { + public: + SystemSchemaLoader(); + + private: + std::string __getSchemaDir(); + Database& __getDatabase(); + }; + + class UserSchemaLoader : public SchemaLoader { + public: + UserSchemaLoader(); + + private: + std::string __getSchemaDir(); + Database& __getDatabase(); + }; +} + +#endif /* __CONTEXT_STORE_SCHEMA_LOADER_H__ */ -- 2.7.4