[dali_1.4.26] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / plugins / dali-script-v8 / src / shared / object-template-helper.cpp
1 /*
2  * Copyright (c) 2015 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 // HEADER
19 #include "object-template-helper.h"
20
21 // INTERNAL INCLUDES
22 #include <v8-utils.h>
23 #include <signals/signal-manager.h>
24
25
26 namespace Dali
27 {
28
29 namespace V8Plugin
30 {
31
32 namespace ObjectTemplateHelper
33 {
34
35 void AddSignalConnectAndDisconnect( v8::Isolate* isolate,  v8::Local<v8::ObjectTemplate>& objTemplate )
36 {
37   objTemplate->Set( v8::String::NewFromUtf8( isolate, "on"),
38                      v8::FunctionTemplate::New( isolate, SignalManager::SignalConnect) );
39
40
41
42   objTemplate->Set( v8::String::NewFromUtf8( isolate, "off"),
43                      v8::FunctionTemplate::New( isolate, SignalManager::SignalDisconnect) );
44 }
45
46
47
48
49 void InstallFunctions( v8::Isolate* isolate,
50                               v8::Local<v8::ObjectTemplate>& objTemplate,
51                               const ApiFunction* functionTable,
52                               unsigned int tableCount,
53                               FunctionType type )
54 {
55   // add our function properties
56    for( unsigned int i = 0; i < tableCount; ++i )
57    {
58      const ApiFunction property =  functionTable[i];
59
60      std::string funcName;
61
62      if( type == NORMAL_FUNCTIONS )
63      {
64        funcName = V8Utils::GetJavaScriptFunctionName( property.name);
65      }
66      else
67      {
68
69        funcName = property.name;
70      }
71     // printf("Installing function %s \n",      funcName.c_str()     );
72      objTemplate->Set( v8::String::NewFromUtf8(   isolate, funcName.c_str() ),
73                       v8::FunctionTemplate::New( isolate, property.function ) );
74    }
75 }
76
77 } // ObjectTemplateHelper
78
79 } // V8Plugin
80
81 } // Dali