aboutsummaryrefslogtreecommitdiffstats
path: root/src/bindings/eldbus_js/eldbus_js_message.cc
blob: f9cfa40b7660659b4068d37037c02b616ed7fb5b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <Eldbus_Js.hh>

namespace efl { namespace eldbus { namespace js {

namespace {

void register_message_method_call_new(v8::Isolate *isolate,
                                      v8::Handle<v8::Object> global,
                                      v8::Handle<v8::String> name)
{
    using v8::String;
    using v8::FunctionTemplate;

    auto f = [](compatibility_callback_info_type args)
        -> compatibility_return_type {
        if (args.Length() != 4 || !args[0]->IsString() || !args[1]->IsString()
            || !args[2]->IsString() || !args[3]->IsString()) {
            return compatibility_return();
        }

        auto isolate = args.GetIsolate();
        auto ret = eldbus_message_method_call_new(*String::Utf8Value(args[0]),
                                                  *String::Utf8Value(args[1]),
                                                  *String::Utf8Value(args[2]),
                                                  *String::Utf8Value(args[3]));
        return compatibility_return(wrap_eldbus_msg(ret, isolate), args);
    };

    global->Set(name,
                compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
}

void register_message_error_new(v8::Isolate *isolate,
                                v8::Handle<v8::Object> global,
                                v8::Handle<v8::String> name)
{
    using v8::String;
    using v8::FunctionTemplate;

    auto f = [](compatibility_callback_info_type args)
        -> compatibility_return_type {
        if (args.Length() != 3 || !args[0]->IsObject() || !args[1]->IsString()
            || !args[2]->IsString()) {
            return compatibility_return();
        }

        auto isolate = args.GetIsolate();
        auto ret = eldbus_message_error_new(extract_eldbus_msg(args[0]
                                                               ->ToObject()),
                                            *String::Utf8Value(args[1]),
                                            *String::Utf8Value(args[2]));
        return compatibility_return(wrap_eldbus_msg(ret, isolate), args);
    };

    global->Set(name,
                compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
}

void register_message_method_return_new(v8::Isolate *isolate,
                                        v8::Handle<v8::Object> global,
                                        v8::Handle<v8::String> name)
{
    using v8::String;
    using v8::FunctionTemplate;

    auto f = [](compatibility_callback_info_type args)
        -> compatibility_return_type {
        if (args.Length() != 1 || !args[0]->IsObject())
            return compatibility_return();

        auto isolate = args.GetIsolate();
        auto eldbus_msg = extract_eldbus_msg(args[0]->ToObject());
        auto ret = eldbus_message_method_return_new(eldbus_msg);
        return compatibility_return(wrap_eldbus_msg(ret, isolate), args);
    };

    global->Set(name,
                compatibility_new<FunctionTemplate>(isolate, f)->GetFunction());
}

}

EAPI
void register_eldbus_message(v8::Isolate* isolate, v8::Handle<v8::Object> exports)
{
  register_message_method_call_new
    (isolate, exports, compatibility_new<v8::String>
     (isolate, "message_method_call_new"));

  register_message_error_new
    (isolate, exports, compatibility_new<v8::String>
     (isolate, "message_error_new"));

  register_message_method_return_new
    (isolate, exports, compatibility_new<v8::String>
     (isolate, "message_method_return_new"));
}

} } } // namespace efl { namespace eldbus { namespace js {