1 #ifndef __DALI_V8PLUGIN_BASE_WRAPPED_OBJECT_H__
2 #define __DALI_V8PLUGIN_BASE_WRAPPED_OBJECT_H__
5 * Copyright (c) 2015 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
97 KEYBOARD_FOCUS_MANAGER,
99 ////////////////////////////////////////////////////////
100 PROPERTY_VALUE_START_RANGE, // start of property values
108 PROPERTY_VALUE_END_RANGE, // end of property values
109 ///////////////////////////////////////////////////////
113 * A type enum for the wrapped object internal field
119 FIELD_COUNT = 2 // increase if more fields are added
123 * @brief virtual destructor
125 virtual ~BaseWrappedObject();
128 * @return true if nothing else is referencing this object
133 * @brief Called when the v8 garbage collector decides the JavaScript object (which contains the Dali wrapped object)
134 * is no longer used / reachable.
136 static void WeakCallback( const v8::WeakCallbackData<v8::Object,BaseWrappedObject >& data);
139 * @brief create and set the internal fields of a JavaScript object.
140 * Currently has 2 internal fields, 1 is a pointer to dali wrapped object, 2nd is the type.
142 void SetJavascriptObject( v8::Isolate* isolate, v8::Local<v8::Object>& object );
145 * @return true if the object is of a certain wrapped type (e.g. Animation )
147 static bool IsWrappedType( v8::Isolate* isolate, const v8::Local<v8::Object>& object, BaseWrappedObject::Type type);
150 * @return true if the object is a wrapped property value
152 static bool IsWrappedTypeAPropertyValue(const v8::Local<v8::Object>& object);
155 * @brief Extracts the Dali wrapped object from the javascript object
157 static BaseWrappedObject* UnWrap( v8::Isolate* isolate, const v8::Local<v8::Object>& object);
160 * @return the wrapped type
164 virtual SignalManager* GetSignalManager();
170 * @param type wrapped type
171 * @param gc garbage collector interface
173 BaseWrappedObject( Type type, GarbageCollectorInterface& gc );
180 * We store a persistent handle to the JavaScript object and then set it to weak.
181 * This means we be notified when v8 decides it's no longer required and we can delete
182 * the associated Dali object
184 v8::Persistent<v8::Object > mWeakPersistentHandle;
185 Type mWrappedType; ///< wrapped type
186 GarbageCollectorInterface& mGarbageCollector; ///< Dali garbage collector
193 #endif // header __DALI_V8PLUGIN_DALI_OBJECT_LIFETIME_MANAGER_H__