Merge branch 'j-h-choi-tizen' into tizen
[platform/core/dotnet/launcher.git] / NativeLauncher / installer-plugin / prefer_dotnet_aot_plugin.cc
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "ni_common.h"
18 #include "log.h"
19 #include "utils.h"
20
21 #ifdef  LOG_TAG
22 #undef  LOG_TAG
23 #endif
24 #define LOG_TAG "NETCORE_INSTALLER_PLUGIN"
25
26 #include <cstring>
27 #include <vector>
28 #include <sstream>
29 #include <glib.h>
30
31 typedef struct Metadata {
32         const char *key;
33         const char *value;
34 } Metadata;
35
36 extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *appId, GList *list)
37 {
38         GList *tag = NULL;
39         bool mdValue = false;
40         Metadata *mdInfo = NULL;
41         tag = g_list_first(list);
42         while (tag) {
43                 mdInfo = (Metadata*)tag->data;
44                 if (strcmp(mdInfo->key, AOT_METADATA_KEY) == 0 && strcmp(mdInfo->value, AOT_METADATA_VALUE) == 0) {
45                         _DBG("Prefer dotnet application AOT set TRUE");
46                         mdValue = true;
47                 }
48                 tag = g_list_next(tag);
49         }
50
51         if (mdValue) {
52                 NiCommonOption option = {std::string(), std::string(), std::string()};
53                 if (initNICommon(&option) < 0) {
54                         _ERR("Fail to initialize NI Common");
55                         return -1;
56                 }
57
58                 if (createNiUnderPkgRoot(pkgId, false) != 0) {
59                         _ERR("Failed to get root path from [%s]", pkgId);
60                         return -1;
61                 } else {
62                         _INFO("Complete make application to native image");
63                 }
64         }
65         return 0;
66 }
67
68 extern "C" int PKGMGR_MDPARSER_PLUGIN_UPGRADE(const char *pkgId, const char *appId, GList *list)
69 {
70         return PKGMGR_MDPARSER_PLUGIN_INSTALL(pkgId, appId, list);
71 }
72
73 extern "C" int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgId, const char *appId, GList *list)
74 {
75         return 0;
76 }
77
78 extern "C" int PKGMGR_MDPARSER_PLUGIN_REMOVED(const char *pkgId, const char *appId, GList *list)
79 {
80         return PKGMGR_MDPARSER_PLUGIN_UPGRADE(pkgId, appId, list);
81 }
82
83 extern "C" int PKGMGR_MDPARSER_PLUGIN_CLEAN(const char *pkgId, const char *appId, GList *list)
84 {
85         return 0;
86 }
87
88 extern "C" int PKGMGR_MDPARSER_PLUGIN_UNDO(const char *pkgId, const char *appId, GList *list)
89 {
90         return 0;
91 }