Imported Upstream version 0.9.2
[platform/upstream/iotivity.git] / service / protocol-plugin / plugin-manager / src / Android / src / org / iotivity / service / ppm / PluginManager.java
1 //******************************************************************
2 //
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 /// @file PluginManager.java
22
23 /// @brief After installing a plug-in in a directory, each plug-in can be managed by this class.
24
25 package org.iotivity.service.ppm;
26
27 import android.content.Context;
28 import android.util.Log;
29
30 public class PluginManager {
31
32     /**
33     * Start plug-ins by key-value pair.
34     *
35     * @param key    - key information of the plug-in to be started.
36     * @param value   - value information of the plug-in to be started.
37     * @return int   - 1 on success or 0 on failure.
38     */
39     public int startPlugins(String key, String value) {
40         LogEx("startPlugins() Called.");
41         return jniStartPlugins(key, value);
42     }
43
44     /**
45     * Stop plug-ins by key-value pair.
46     *
47     * @param key    - key information of the plug-in to be stopped.
48     * @param value   - value information of the plug-in to be stopped.
49     * @return int   - 1 on success or 0 on failure.
50     */
51     public int stopPlugins(String key, String value) {
52         LogEx("stopPlugins() Called.");
53         return jniStopPlugins(key, value);
54     }
55
56     /**
57     * Rescan for plug-ins in the registered directory and install plug-ins.
58     *
59     * @param void
60     * @return int   - 1 on success or 0 on failure.
61     */
62     public int rescanPlugin() {
63         LogEx("rescanPlugin() Called.");
64         return jniRescanPlugin();
65     }
66
67     /**
68     * Get list of plug-ins.
69     *
70     * @param void
71     * @return Plugin[]   - Plug-in array.
72     */
73     public Plugin[] getPlugins() {
74         LogEx("getPlugins() Called.");
75         return jniGetPlugins();
76     }
77
78     /**
79     * Get state of the plug-in.
80     *
81     * @param pluginID       - ID of the plug-in to get state.
82     * @return String   - state of the plug-in.
83     */
84     public String getState(String plugID) {
85         LogEx("getState() Called.");
86         return jniGetState(plugID);
87     }
88
89     public PluginManager(Context ctx) {
90         LogEx("PluginManager() Called.");
91         FelixManager.getInstance(ctx);
92         System.loadLibrary("PluginManager");
93     }
94
95     private static final String LOG_TAG = "PPMSampleApp : PluginManager";
96
97     private native int jniStartPlugins(String key, String value);
98
99     private native int jniStopPlugins(String key, String value);
100
101     private native int jniRescanPlugin();
102
103     private native Plugin[] jniGetPlugins();
104
105     private native String jniGetState(String plugID);
106
107     private static void LogEx(String info) {
108         Log.d(LOG_TAG, info);
109     }
110 }