Release version 0.15.20
[platform/core/appfw/launchpad.git] / src / common / src / launchpad_plugin.c
1 /*
2  * Copyright (c) 2020 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 #define _GNU_SOURCE
18 #include <dlfcn.h>
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <unistd.h>
23
24 #include "launchpad_plugin.h"
25 #include "log_private.h"
26
27 #define PATH_LAUNCHPAD_PLUGIN "/usr/share/aul/plugin/liblaunchpad-plugin.so"
28 #define TAG_LAUNCHPAD_PLUGIN_PREPARE_APP "LAUNCHPAD_PLUGIN_PREPARE_APP"
29
30 int _launchpad_plugin_prepare_app(const char *app_id, bundle *kb)
31 {
32         void *handle;
33         int (*prepare_app)(const char *, bundle *);
34         int ret;
35
36         ret = access(PATH_LAUNCHPAD_PLUGIN, F_OK);
37         if (ret != 0) {
38                 if (errno != ENOENT)
39                         _W("plugin module does not exist. errno(%d)", errno);
40                 return 0;
41         }
42
43         handle = dlopen(PATH_LAUNCHPAD_PLUGIN, RTLD_LAZY | RTLD_LOCAL);
44         if (!handle) {
45                 _W("Failed to open plugin so. error(%s)", dlerror());
46                 return 0;
47         }
48
49         prepare_app = dlsym(handle, TAG_LAUNCHPAD_PLUGIN_PREPARE_APP);
50         if (!prepare_app) {
51                 _W("Failed to load %s", TAG_LAUNCHPAD_PLUGIN_PREPARE_APP);
52                 dlclose(handle);
53                 return 0;
54         }
55
56         _W("LAUNCHPAD_PLUGIN_PREPARE_APP ++");
57         ret = prepare_app(app_id, kb);
58         _W("LAUNCHPAD_PLUGIN_PREPARE_APP --");
59         if (ret != 0)
60                 return -1;
61
62         return 0;
63 }