Revert "Implementation of IPC Asynchronous Message Support."
[platform/framework/web/wrt-plugins-common.git] / src / Commons / JSObjectDeclaration.h
1 /*
2  * Copyright (c) 2011 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  * @file    js_object_declaration.h
18  * @author  Grzegorz Krawczyk (g.krawczyk@samgsung.com)
19  * @version
20  * @brief
21  */
22
23 #ifndef WRT_SRC_PLUGIN_SERVICE_JS_OBJECT_DECLARATION_H_
24 #define WRT_SRC_PLUGIN_SERVICE_JS_OBJECT_DECLARATION_H_
25
26 #include <string>
27 #include <memory>
28 #include <cassert>
29 #include <dpl/shared_ptr.h>
30 #include <dpl/noncopyable.h>
31 #include <dpl/log/log.h>
32 #include <wrt_plugin_export.h>
33
34 class JSObjectDeclaration : private DPL::Noncopyable
35 {
36   public:
37     typedef const void* ConstClassTemplate;
38     typedef void* ClassTemplate;
39     typedef js_class_constructor_cb_t ConstructorCallback;
40     typedef class_definition_options_t ClassOptions;
41
42     class Options : DPL::Noncopyable
43     {
44       public:
45         enum class ClassType
46         {
47             Class,
48             Function,
49             Interface
50         };
51
52         enum class IFrameObject
53         {
54             None,
55             Reference,
56             CreateInstance
57         };
58
59         enum class IFrameNotice
60         {
61             None,
62             AlwaysNotice
63         };
64
65         //only for function
66         enum class IFrameOverlay
67         {
68             Ignored,
69             UseOverlayed,
70             OverlayedBeforeOriginal
71         };
72
73         typedef js_object_instance_t ObjectInstance;
74         typedef java_script_context_t JsContext;
75         typedef void* PrivateData;
76
77       public:
78         ClassType getType() const;
79
80         IFrameObject getIframeObject() const;
81         IFrameNotice getIframeNotice() const;
82         IFrameOverlay getIframeOverlay() const;
83         js_function_impl getFunctionImpl() const;
84
85         void invokeCallback(JsContext ctx,
86                             ObjectInstance iframe,
87                             ObjectInstance object) const;
88
89         PrivateData getPrivateData() const;
90
91       private:
92         const ClassOptions* m_options;
93
94       private:
95         explicit Options(const ClassOptions* options) : m_options(options)
96         {
97             assert(options && "Dont create empty options");
98         }
99
100         friend class JSObjectDeclaration;
101     };
102
103     typedef std::shared_ptr<Options> OptionsPtr;
104
105   public:
106
107     explicit JSObjectDeclaration(js_entity_definition_ptr_t declaration);
108
109     virtual const std::string& getName() const
110     {
111         return m_name;
112     }
113
114     virtual const std::string& getParentName() const
115     {
116         return m_parentName;
117     }
118
119     virtual ConstClassTemplate getClassTemplate() const
120     {
121         return m_classTemplate;
122     }
123
124     virtual const std::string& getInterfaceName() const
125     {
126         return m_interfaceName;
127     }
128
129     virtual ConstructorCallback getConstructorCallback() const
130     {
131         return m_constructorCallback;
132     }
133
134     const OptionsPtr getOptions() const
135     {
136         return m_options;
137     }
138
139     bool checkIframesSupported() const;
140
141     virtual ~JSObjectDeclaration();
142
143   private:
144     std::string m_name;
145     std::string m_parentName;
146     std::string m_interfaceName;
147     ConstClassTemplate m_classTemplate;
148     ConstructorCallback m_constructorCallback;
149     OptionsPtr m_options;
150 };
151
152 typedef DPL::SharedPtr<JSObjectDeclaration> JSObjectDeclarationPtr;
153
154 #endif