JavaScript support for DALi
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / scripting / script-impl.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
18 // CLASS HEADER
19 #include "script-impl.h"
20
21 // INTERNAL INCLUDES
22 #include <dali/integration-api/debug.h>
23 #include "script-plugin-proxy.h"
24
25 namespace Dali
26 {
27
28 namespace Toolkit
29 {
30
31 namespace Internal
32 {
33
34 namespace
35 {
36 const char* PLUGIN_FILE = "libdali-script-plugin-v8.so";
37 }
38
39 void Script::ExecuteFile( const std::string& filename )
40 {
41   if( mPlugin )
42   {
43     mPlugin->ExecuteFile(filename);
44   }
45 }
46
47 Script::Script(void) : mPlugin(NULL)
48 {
49   ScriptPluginProxy *plugin = new ScriptPluginProxy( PLUGIN_FILE );
50
51   if( mPlugin )
52   {
53     DALI_LOG_WARNING("Reloading script plugin %s, is this what you wanted to do?",PLUGIN_FILE);
54     delete mPlugin;
55     mPlugin = NULL;
56   }
57
58   if( plugin->IsInitialized() )
59   {
60     mPlugin = plugin;
61   }
62   else
63   {
64     delete plugin;
65   }
66
67 }
68
69 Script::~Script()
70 {
71   if( mPlugin )
72   {
73     delete mPlugin;
74   }
75 }
76
77 } // namespace Internal
78
79 } // namespace Toolkit
80
81 } // namespace Dali