summaryrefslogtreecommitdiff
path: root/src/plugin-loading/plugin.h
blob: 0eaa1a59a7c98d9b365b6a1f00b6d06d7a722c8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
 *
 *    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.
 */
/**
 * @file        plugin.h
 * @author      Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
 * @version     1.0
 * @brief       This file is the implementation file of plugin
 */
#ifndef WRT_SRC_PLUGIN_SERVICE_PLUGIN_H_
#define WRT_SRC_PLUGIN_SERVICE_PLUGIN_H_

#include <list>
#include <map>
#include <string>
#include <dpl/atomic.h>
#include <memory>
#include <dpl/noncopyable.h>
#include <wrt_plugin_export.h>
#include <Commons/JSObjectDeclaration.h>
#include <dpl/wrt-dao-ro/wrt_db_types.h>

class Plugin;
typedef std::shared_ptr<Plugin> PluginPtr;

class Plugin : private DPL::Noncopyable
{
  public:
    typedef JSObjectDeclaration Class;
    typedef JSObjectDeclarationPtr ClassPtr;
    typedef std::list<ClassPtr> ClassList;
    typedef std::shared_ptr<ClassList> ClassPtrList;

  private:
    ///< Plug-in identifier. Currently plug-in file name is used as the ID
    std::string m_fileName;

    ///< Handle for the plug-in library. A plug-in is a dynamic loadable library
    void* m_libHandle;

    // Plugin API
    on_widget_start_proc* m_apiOnWidgetStart;
    on_widget_init_proc* m_apiOnWidgetInit;
    on_widget_stop_proc* m_apiOnWidgetStop;
    on_frame_load_proc* m_apiOnFrameLoad;
    on_frame_unload_proc* m_apiOnFrameUnload;
    const ClassPtrList m_apiClassList;

    Plugin(const std::string &fileName,
           void *libHandle,
           on_widget_start_proc* apiOnWidgetStart,
           on_widget_init_proc* apiOnWidgetInit,
           on_widget_stop_proc* apiOnWidgetStop,
           on_frame_load_proc* apiOnFrameLoad,
           on_frame_unload_proc* apiOnFrameUnload,
           const ClassPtrList &apiClassList);

  public:
    virtual ~Plugin();

    // Loading
    static PluginPtr LoadFromFile(const std::string &fileName);

    // Filename
    std::string GetFileName() const;

    // API
    void OnWidgetStart(WidgetHandle widgetId);

    void OnWidgetInit(feature_mapping_interface_t *interface);

    void OnWidgetStop(WidgetHandle widgetId);

    void OnFrameLoad(java_script_context_t context);

    void OnFrameUnload(java_script_context_t context);

    const ClassPtrList GetClassList() const;
};

#endif // PLUGIN_H