1 #ifndef DALI_V8PLUGIN_BASE_WRAPPED_OBJECT_H
2 #define DALI_V8PLUGIN_BASE_WRAPPED_OBJECT_H
5 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
25 #include <interfaces/garbage-collector-interface.h>
37 * @brief Used as a base class for all wrapped objects.
39 * Dali JavaScript objects look like this
42 * _______________________________________ ________________________________________
43 * | JavaScript Object | | C++ WrappedObject (e.g. ImageWrapper)|
44 * |---------------------------------------| |----------------------------------------|
45 * | Hidden internal fields | | Handle to a Dali::Image object |
46 * | *Pointer to a BaseWrappedObject | ----> |________________________________________|
47 * | Type of wrapped object (e.g. Image) |
48 * -----------------------------------------
52 * Whenever we want to access functions / properties of that wrapped object, we unwrap it
53 * to get access to the Dali object.
55 * Each wrapped object registers with Dali garbage collector so they can be deleted
56 * when Dali shuts down
58 class BaseWrappedObject
64 * A type enum for the wrapped object
100 KEYBOARD_FOCUS_MANAGER,
101 PAN_GESTURE_DETECTOR,
102 ////////////////////////////////////////////////////////
103 PROPERTY_VALUE_START_RANGE, // start of property values
111 PROPERTY_VALUE_END_RANGE, // end of property values
112 ///////////////////////////////////////////////////////
116 * A type enum for the wrapped object internal field
122 FIELD_COUNT = 2 // increase if more fields are added
126 * @brief virtual destructor
128 virtual ~BaseWrappedObject();
131 * @return true if nothing else is referencing this object
136 * @brief Called when the v8 garbage collector decides the JavaScript object (which contains the Dali wrapped object)
137 * is no longer used / reachable.
139 static void WeakCallback( const v8::WeakCallbackData<v8::Object,BaseWrappedObject >& data);
142 * @brief create and set the internal fields of a JavaScript object.
143 * Currently has 2 internal fields, 1 is a pointer to dali wrapped object, 2nd is the type.
145 void SetJavascriptObject( v8::Isolate* isolate, v8::Local<v8::Object>& object );
148 * @return true if the object is of a certain wrapped type (e.g. Animation )
150 static bool IsWrappedType( v8::Isolate* isolate, const v8::Local<v8::Object>& object, BaseWrappedObject::Type type);
153 * @return true if the object is a wrapped property value
155 static bool IsWrappedTypeAPropertyValue(const v8::Local<v8::Object>& object);
158 * @brief Extracts the Dali wrapped object from the javascript object
160 static BaseWrappedObject* UnWrap( v8::Isolate* isolate, const v8::Local<v8::Object>& object);
163 * @return the wrapped type
167 virtual SignalManager* GetSignalManager();
173 * @param type wrapped type
174 * @param gc garbage collector interface
176 BaseWrappedObject( Type type, GarbageCollectorInterface& gc );
183 * We store a persistent handle to the JavaScript object and then set it to weak.
184 * This means we be notified when v8 decides it's no longer required and we can delete
185 * the associated Dali object
187 v8::Persistent<v8::Object > mWeakPersistentHandle;
188 Type mWrappedType; ///< wrapped type
189 GarbageCollectorInterface& mGarbageCollector; ///< Dali garbage collector
192 } // namespace V8Plugin
196 #endif // DALI_V8PLUGIN_BASE_WRAPPED_OBJECT_H