Merge branch 'master' of git.sv.gnu.org:/srv/git/gnash
[gnash.git] / extensions / lirc / lirc_ext.cpp
blobdfcfa6ae5d632ed79f23c62f039817442daba25b
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
3 // Foundation, Inc
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #ifdef HAVE_CONFIG_H
21 #include "gnashconfig.h"
22 #endif
24 #include <iostream>
26 #include <cstdarg>
27 #include <cstdio>
28 #include <cstdlib>
30 #include <string>
31 #include "log.h"
32 #include "lirc.h"
33 #include "lirc_ext.h"
34 #include "fn_call.h"
35 #include "as_object.h"
36 #include "Global_as.h"
37 #include "builtin_function.h" // need builtin_function
39 using namespace std;
41 namespace gnash
43 struct lirc_config *config;
44 as_value lirc_ext_init(const fn_call& fn);
45 as_value lirc_ext_getkey(const fn_call& fn);
46 as_value lirc_ext_getbutton(const fn_call& fn);
48 class LircRelay : public Relay
50 public:
51 Lirc obj;
54 static void
55 attachInterface(as_object& obj)
57 GNASH_REPORT_FUNCTION;
58 Global_as& gl = getGlobal(obj);
60 obj.init_member("lirc_init", gl.createFunction(lirc_ext_init));
61 obj.init_member("lirc_getKey", gl.createFunction(lirc_ext_getkey));
62 obj.init_member("lirc_getButton", gl.createFunction(lirc_ext_getbutton));
65 static as_value
66 lirc_ctor(const fn_call& fn)
68 as_object* obj = ensure<ValidThis>(fn);
70 obj->setRelay(new LircRelay());
72 return as_value();
76 Lirc::Lirc()
78 GNASH_REPORT_FUNCTION;
81 Lirc::~Lirc()
83 GNASH_REPORT_FUNCTION;
86 as_value
87 lirc_ext_init(const fn_call& fn)
89 GNASH_REPORT_FUNCTION;
90 LircRelay* ptr = ensure<ThisIsNative<LircRelay> >(fn);
92 if (fn.nargs > 0) {
93 const std::string& text = fn.arg(0).to_string();
94 return as_value(ptr->obj.init(text.c_str()));
96 return as_value(false);
99 as_value
100 lirc_ext_getkey(const fn_call& fn)
102 GNASH_REPORT_FUNCTION;
103 LircRelay* ptr = ensure<ThisIsNative<LircRelay> >(fn);
105 if (fn.nargs == 0) {
106 key::code key = ptr->obj.getKey();
107 return as_value(key);
109 return as_value(false);
112 as_value
113 lirc_ext_getbutton(const fn_call& fn)
115 LircRelay* ptr = ensure<ThisIsNative<LircRelay> >(fn);
116 return as_value(ptr->obj.getButton());
119 extern "C" {
120 void
121 lirc_class_init(as_object &obj)
124 Global_as& gl = getGlobal(obj);
125 as_object* proto = createObject(gl);
126 attachInterface(*proto);
127 as_object* cl = gl.createClass(&lirc_ctor, proto);
128 obj.init_member("Lirc", cl);
130 } // end of extern C
133 } // end of gnash namespace
135 // Local Variables:
136 // mode: C++
137 // indent-tabs-mode: t
138 // End: