[SRUK] Initial copy from Tizen 2.2 version
[platform/core/uifw/dali-core.git] / dali / public-api / actors / custom-actor.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 // CLASS HEADER
18 #include <dali/public-api/actors/custom-actor.h>
19
20 #include <dali/public-api/object/type-registry.h>
21
22 // INTERNAL INCLUDES
23 #include <dali/internal/event/actors/custom-actor-internal.h>
24
25 namespace Dali
26 {
27
28 namespace
29 {
30
31 using namespace Dali;
32
33 BaseHandle Create()
34 {
35   // not directly creatable
36   return BaseHandle();
37 }
38
39 TypeRegistration mType( typeid(Dali::CustomActor), typeid(Dali::Actor), Create );
40
41 }
42
43 CustomActor::CustomActor()
44 {
45 }
46
47 CustomActor CustomActor::DownCast( BaseHandle handle )
48 {
49   return CustomActor( dynamic_cast<Dali::Internal::CustomActor*>(handle.GetObjectPtr()) );
50 }
51
52 CustomActor::~CustomActor()
53 {
54 }
55
56 CustomActorImpl& CustomActor::GetImplementation()
57 {
58   Internal::CustomActor& internal = GetImpl(*this);
59
60   return internal.GetImplementation();
61 }
62
63 const CustomActorImpl& CustomActor::GetImplementation() const
64 {
65   const Internal::CustomActor& internal = GetImpl(*this);
66
67   return internal.GetImplementation();
68 }
69
70 CustomActor::CustomActor(CustomActorImpl& implementation)
71 : Actor(Internal::CustomActor::New(implementation).Get())
72 {
73 }
74
75 CustomActor::CustomActor(Internal::CustomActor* internal)
76 : Actor(internal)
77 {
78   // Check we haven't just constructed a new handle, while in the internal custom actors destructor.
79   // This can happen if the user defined CustomActorImpl destructor calls Self(), to create a new handle
80   // to the CustomActor.
81   //
82   // If it's in the destructor then the ref count is zero, so once we've created a new handle it will be 1
83   // Without this check, the actor will be deleted a second time, when the handle is disposed of
84   // causing a crash.
85
86   if (internal)
87   {
88     DALI_ASSERT_ALWAYS(internal->ReferenceCount() != 1 && "Are you trying to use CustomActorImpl::Self() inside a CustomActorImpl destructor?");
89   }
90 }
91
92 } // namespace Dali