Refactorying files with skeleton codes 88/281588/1
authordyamy-lee <dyamy.lee@samsung.com>
Fri, 2 Sep 2022 08:54:09 +0000 (17:54 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Tue, 20 Sep 2022 04:44:52 +0000 (13:44 +0900)
Following new architecture design for interface,
refatorying files with skeleton codes.

mmi files are related with Reference Apps.
mmi-core files are called from mmi files for real mmi library logic.
mmi-common has structures for mmi library.

Change-Id: I917efe2904112bd14c566d9c282f4d59935ab40f

src/meson.build
src/mmi-common.h [new file with mode: 0644]
src/mmi-core.c [new file with mode: 0644]
src/mmi-core.h [moved from src/mmi-event-types.h with 79% similarity]
src/mmi-ipc.c
src/mmi-ipc.h
src/mmi.c
src/mmi.h
tests/mmi-ipc-test.cpp
tests/mmi-main-test.cpp

index 7a5eb01..13c5ee4 100644 (file)
@@ -5,12 +5,14 @@ mmi_srcs = [
        'mmi-ipc.c',
        'mmi-dbg.h',
        'mmi_proxy.h',
-       'mmi_proxy.c'
+       'mmi_proxy.c',
+       'mmi-core.h',
+       'mmi-core.c',
        ]
 
 install_headers(
        'mmi.h',
-       'mmi-event-types.h'
+       'mmi-common.h'
        )
 
 glib_dep = dependency('glib-2.0', method : 'pkg-config')
diff --git a/src/mmi-common.h b/src/mmi-common.h
new file mode 100644 (file)
index 0000000..9c75979
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+* Copyright © 2021 Samsung Electronics co., Ltd. All Rights Reserved.
+*
+* Permission is hereby granted, free of charge, to any person obtaining a
+* copy of this software and associated documentation files (the "Software"),
+* to deal in the Software without restriction, including without limitation
+* the rights to use, copy, modify, merge, publish, distribute, sublicense,
+* and/or sell copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice (including the next
+* paragraph) shall be included in all copies or substantial portions of the
+* Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+* DEALINGS IN THE SOFTWARE.
+*/
+
+#ifndef __MMI_COMMON_H__
+#define __MMI_COMMON_H__
+
+#include <tizen.h>
+
+#define MMI_API __attribute__ ((visibility("default")))
+
+typedef void* mmi_rpc_h;
+
+typedef enum {
+       MMI_RESULT_NONE,
+       MMI_RESULT_FAIL,
+       MMI_RESULT_SUCCESS
+} mmi_result_e;
+
+typedef enum {
+       MMI_STATE_NONE,
+} mmi_state_e;
+
+typedef enum {
+       MMI_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
+       MMI_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of Memory */
+       MMI_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< I/O error */
+       MMI_ERROR_INVALID_PARAMETER     = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
+       MMI_ERROR_OUT_OF_NETWORK = TIZEN_ERROR_NETWORK_DOWN, /**< Network is down */
+       MMI_ERROR_TIMED_OUT = TIZEN_ERROR_TIMED_OUT, /**< No answer from the daemon */
+       MMI_ERROR_PERMISSION_DENIED     = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */
+       MMI_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< MMI NOT supported */
+} mmi_error_e;
+
+typedef struct {
+       mmi_rpc_h rpc_h;
+       const char *stub_appid;
+       int state;
+} mmi_struct_s;
+
+typedef mmi_struct_s* mmi_handle;
+
+#endif //__MMI_COMMON_H__
diff --git a/src/mmi-core.c b/src/mmi-core.c
new file mode 100644 (file)
index 0000000..8490bb2
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+* Copyright © 2022 Samsung Electronics co., Ltd. All Rights Reserved.
+*
+* Permission is hereby granted, free of charge, to any person obtaining a
+* copy of this software and associated documentation files (the "Software"),
+* to deal in the Software without restriction, including without limitation
+* the rights to use, copy, modify, merge, publish, distribute, sublicense,
+* and/or sell copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice (including the next
+* paragraph) shall be included in all copies or substantial portions of the
+* Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+* DEALINGS IN THE SOFTWARE.
+*/
+
+#include "mmi-ipc.h"
+#include "mmi-dbg.h"
+
+static mmi_handle mmi_h = NULL;
+
+int mmi_instance_create(void)
+{
+       mmi_h = (mmi_handle)calloc(1, sizeof(mmi_struct_s));
+
+       if (mmi_h == NULL) {
+               LOGE("Failed to allocate memory for mmi_h !\n");
+               return MMI_ERROR_OUT_OF_MEMORY;
+       }
+
+       if (mmi_ipc_init()) {
+               LOGE("Failed to init mmi ipc !\n");
+               if(mmi_h != NULL) {
+                       free(mmi_h);
+                       mmi_h = NULL;
+               }
+               return MMI_ERROR_NOT_SUPPORTED;
+       }
+
+       mmi_h->rpc_h = mmi_ipc_get_rpc_h();
+       mmi_h->stub_appid = mmi_ipc_get_stub_appid();
+       mmi_h->state = mmi_ipc_get_state();
+
+       return MMI_ERROR_NONE;
+}
+
+int mmi_instance_destroy()
+{
+       if (mmi_h == NULL) {
+               LOGE("A mmi_h is already NULL");
+               return MMI_ERROR_NONE;
+       }
+
+       mmi_ipc_shutdown();
+       free(mmi_h);
+       mmi_h = NULL;
+
+       return MMI_ERROR_NONE;
+}
similarity index 79%
rename from src/mmi-event-types.h
rename to src/mmi-core.h
index 2f30fb4..cb3bfdc 100644 (file)
@@ -1,5 +1,5 @@
 /*
-* Copyright © 2021 Samsung Electronics co., Ltd. All Rights Reserved.
+* Copyright © 2022 Samsung Electronics co., Ltd. All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * DEALINGS IN THE SOFTWARE.
 */
 
-#ifndef __MMI_EVENT_TYPES_H__
-#define __MMI_EVENT_TYPES_H__
+#ifndef __MMI_CORE_H__
+#define __MMI_CORE_H__
 
-#include <stdbool.h>
+#include "mmi-common.h"
 
-typedef struct
-{
-   bool connected;
-} mmi_event_connection;
+#ifdef __cplusplus
+extern "C" {
+#endif
 
-#endif //__MMI_EVENT_TYPES_H__
+int mmi_instance_create(void);
+int mmi_instance_destroy();
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //__MMI_CORE_H__
\ No newline at end of file
index 7be787a..902cda8 100644 (file)
@@ -33,7 +33,7 @@
 static rpc_port_proxy_mmi_h _rpc_h;
 static const char* _stub_appid = "mmi-manager";
 static int _connected = 0;
-static mmi_state _state = MMI_STATE_NONE;
+static mmi_state_e _state = MMI_STATE_NONE;
 
 rpc_port_proxy_mmi_h
 mmi_ipc_get_rpc_h(void)
@@ -41,8 +41,7 @@ mmi_ipc_get_rpc_h(void)
        return _rpc_h;
 }
 
-mmi_state
-mmi_ipc_get_state(void)
+mmi_state_e mmi_ipc_get_state(void)
 {
        return _state;
 }
@@ -62,39 +61,15 @@ mmi_ipc_get_stub_appid(void)
 static void _on_connected(rpc_port_proxy_mmi_h h, void *user_data)
 {
        int r;
-       mmi_event_connection *ev = NULL;
-
-       ev = (mmi_event_connection *)calloc(1, sizeof(mmi_event_connection));
-
-       if (!ev)
-       {
-               LOGE("Failed to allocate memory for connection event !\n");
-               return;
-       }
        _connected = 1;
-       ev->connected = true;
 
        LOGI("...");
        return;
-err:
-       if (ev)
-               free(ev);
 }
 
 static void _on_disconnected(rpc_port_proxy_mmi_h h, void *user_data)
 {
-       mmi_event_connection *ev = NULL;
-
-       ev = (mmi_event_connection *)calloc(1, sizeof(mmi_event_connection));
-
-       if (!ev)
-       {
-               LOGE("Failed to allocate memory for connection event !\n");
-               return;
-       }
-
        _connected = 0;
-       ev->connected = false;
 
        LOGI("...");
 }
index 6cbb685..0f90d7a 100644 (file)
@@ -25,6 +25,7 @@
 #define __MMI_IPC_H__
 
 #include "mmi_proxy.h"
+#include "mmi-common.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -34,7 +35,7 @@ int mmi_ipc_init(void);
 void mmi_ipc_shutdown(void);
 
 rpc_port_proxy_mmi_h mmi_ipc_get_rpc_h(void);
-mmi_state mmi_ipc_get_state(void);
+mmi_state_e mmi_ipc_get_state(void);
 int mmi_ipc_get_uid(void);
 bool mmi_ipc_is_connected(void);
 const char *mmi_ipc_get_appid(void);
index 8832ed5..b2821da 100644 (file)
--- a/src/mmi.c
+++ b/src/mmi.c
 */
 
 #include "mmi.h"
-#include "mmi-ipc.h"
+#include "mmi-core.h"
 #include "mmi-dbg.h"
 
-#define ERR(x)
-
-static int _mmi_init_count = 0;
-
-MMI_API int
-mmi_init(void)
-{
-       return 1;
-}
-
-MMI_API int
-mmi_shutdown(void)
-{
-       return 0;
-}
-
-MMI_API mmi_handle
-mmi_instance_create(void)
+MMI_API int mmi_init(void)
 {
-       mmi_handle h = NULL;
-
-       h = (mmi_handle)calloc(1, sizeof(mmi_struct));
-
-       if (!h)
-       {
-               ERR("Failed to allocate memory for mmi_handle !\n");
-               return NULL;
-       }
-
-       if (mmi_ipc_init())
-       {
-               ERR("Failed to init mmi ipc !\n");
-               goto err;
+       int ret = mmi_instance_create();
+       if(ret != MMI_ERROR_NONE) {
+               LOGE("Fail to create mmi handle instance(%d)", ret);
+               return MMI_ERROR_NOT_SUPPORTED;
        }
 
-       h->rpc_h = mmi_ipc_get_rpc_h();
-       h->stub_appid = mmi_ipc_get_stub_appid();
-       h->state = mmi_ipc_get_state();
-
-       return h;
-err:
-       if (h)
-               free(h);
-       return NULL;
+       return MMI_ERROR_NONE;
 }
 
-MMI_API void
-mmi_instance_destroy(mmi_handle *h)
+MMI_API int mmi_shutdown(void)
 {
-       if (!h)
-               return;
+       int ret = mmi_instance_destroy();
+       if(ret != MMI_ERROR_NONE) {
+               LOGE("Fail to destroy mmi handle instance(%d)", ret);
+               return MMI_ERROR_NOT_SUPPORTED;
+       }
 
-       mmi_ipc_shutdown();
-       free(*h);
-       *h = NULL;
+       return MMI_ERROR_NONE;
 }
-
index b100f20..31ef08f 100644 (file)
--- a/src/mmi.h
+++ b/src/mmi.h
 #ifndef __MMI_H__
 #define __MMI_H__
 
-#include <mmi-event-types.h>
-
-#define MMI_API __attribute__ ((visibility("default")))
-
-typedef void* mmi_rpc_h;
-
-typedef enum
-{
-       MMI_RESULT_NONE,
-       MMI_RESULT_FAIL,
-       MMI_RESULT_SUCCESS
-} mmi_result;
-
-typedef enum
-{
-       MMI_STATE_NONE,
-} mmi_state;
-
-typedef struct
-{
-       mmi_rpc_h rpc_h;
-       const char *stub_appid;
-       int state;
-} mmi_struct;
-
-typedef mmi_struct* mmi_handle;
+#include "mmi-common.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -57,11 +32,9 @@ extern "C" {
 
 MMI_API int mmi_init(void);
 MMI_API int mmi_shutdown(void);
-MMI_API mmi_handle mmi_instance_create(void);
-MMI_API void mmi_instance_destroy(mmi_handle *h);
 
 #ifdef __cplusplus
 }
 #endif
 
-#endif //__MMIFW_H__
+#endif //__MMI_H__
index eedff15..6adbc40 100644 (file)
@@ -46,18 +46,16 @@ TEST_F(MMIIpcTest, MMIFWIpcInitSuccess)
 {
        int res = mmi_init();
 
-       EXPECT_EQ(res, 1);
+       EXPECT_EQ(res, MMI_ERROR_NONE);
 
-       if(res)
-               mmi_shutdown();
+       mmi_shutdown();
 }
 
 TEST_F(MMIIpcTest, MMIIpcInitFail)
 {
        int res = mmi_init();
 
-       EXPECT_EQ(res, 1);
+       EXPECT_EQ(res, MMI_ERROR_NONE);
 
-       if(res)
-               mmi_shutdown();
+       mmi_shutdown();
 }
index e581fb0..cfaccbc 100644 (file)
@@ -22,6 +22,7 @@
 */
 
 #include "mmi.h"
+#include "mmi-core.h"
 #include "mmi-tests.h"
 #include "mmi-ipc.h"
 
@@ -46,8 +47,16 @@ TEST_F(MMIMainTest, MMIMainInit)
 {
        int res = mmi_init();
 
-       EXPECT_EQ(res, 1);
+       EXPECT_EQ(res, MMI_ERROR_NONE);
 
-       if(res)
-               mmi_shutdown();
+       mmi_shutdown();
+}
+
+TEST_F(MMIMainTest, MmiInstanceCreateSuccess)
+{
+       int res = mmi_instance_create();
+
+       EXPECT_EQ(res, MMI_ERROR_NONE);
+
+       mmi_instance_destroy();
 }