1+ // Client module for the OBS Studio node module.
2+ // Copyright(C) 2017 Streamlabs (General Workings Inc)
3+ //
4+ // This program is free software; you can redistribute it and/or
5+ // modify it under the terms of the GNU General Public License
6+ // as published by the Free Software Foundation; either version 2
7+ // of the License, or (at your option) any later version.
8+ //
9+ // This program is distributed in the hope that it will be useful,
10+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
12+ // GNU General Public License for more details.
13+ //
14+ // You should have received a copy of the GNU General Public License
15+ // along with this program; if not, write to the Free Software
16+ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 - 1301, USA.
17+
18+ #include < condition_variable>
19+ #include < mutex>
20+ #include < string>
21+ #include " controller.hpp"
22+ #include " error.hpp"
23+ #include " ipc-value.hpp"
24+ #include " shared.hpp"
25+ #include " utility.hpp"
26+ #include " module.hpp"
27+
28+ osn::Module::Module (uint64_t id)
29+ {
30+ this ->moduleId = id;
31+ }
32+
33+ Nan::Persistent<v8::FunctionTemplate> osn::Module::prototype = Nan::Persistent<v8::FunctionTemplate>();
34+
35+ void osn::Module::Register (Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE target)
36+ {
37+ auto fnctemplate = Nan::New<v8::FunctionTemplate>();
38+ fnctemplate->InstanceTemplate ()->SetInternalFieldCount (1 );
39+ fnctemplate->SetClassName (Nan::New<v8::String>(" Module" ).ToLocalChecked ());
40+
41+ utilv8::SetTemplateField (fnctemplate, " open" , Open);
42+
43+ v8::Local<v8::Template> objtemplate = fnctemplate->PrototypeTemplate ();
44+ utilv8::SetTemplateField (objtemplate, " initialize" , Initialize);
45+
46+ utilv8::SetTemplateAccessorProperty (objtemplate, " name" , Name);
47+ utilv8::SetTemplateAccessorProperty (objtemplate, " fileName" , FileName);
48+ utilv8::SetTemplateAccessorProperty (objtemplate, " author" , Author);
49+ utilv8::SetTemplateAccessorProperty (objtemplate, " description" , Description);
50+ utilv8::SetTemplateAccessorProperty (objtemplate, " binaryPath" , BinaryPath);
51+ utilv8::SetTemplateAccessorProperty (objtemplate, " dataPath" , DataPath);
52+
53+ utilv8::SetObjectField (target, " Module" , fnctemplate->GetFunction ());
54+ prototype.Reset (fnctemplate);
55+ }
56+
57+ Nan::NAN_METHOD_RETURN_TYPE osn::Module::Open (Nan::NAN_METHOD_ARGS_TYPE info)
58+ {
59+ std::string bin_path, data_path;
60+
61+ ASSERT_INFO_LENGTH (info, 2 );
62+ ASSERT_GET_VALUE (info[0 ], bin_path);
63+ ASSERT_GET_VALUE (info[1 ], data_path);
64+
65+ auto conn = GetConnection ();
66+ if (!conn)
67+ return ;
68+
69+ std::vector<ipc::value> response = conn->call_synchronous_helper (" Module" , " Open" , {ipc::value (bin_path), ipc::value (data_path)});
70+
71+ if (!ValidateResponse (response))
72+ return ;
73+
74+ osn::Module* obj = new osn::Module (response[1 ].value_union .ui64 );
75+ info.GetReturnValue ().Set (osn::Module::Store (obj));
76+ }
77+
78+ Nan::NAN_METHOD_RETURN_TYPE osn::Module::Initialize (Nan::NAN_METHOD_ARGS_TYPE info)
79+ {
80+ osn::Module* module ;
81+ if (!utilv8::SafeUnwrap (info, module )) {
82+ return ;
83+ }
84+
85+ auto conn = GetConnection ();
86+ if (!conn)
87+ return ;
88+
89+ std::vector<ipc::value> response =
90+ conn->call_synchronous_helper (" Module" , " Initialize" , {ipc::value (module ->moduleId )});
91+
92+ if (!ValidateResponse (response))
93+ return ;
94+
95+ info.GetReturnValue ().Set (response[1 ].value_union .i32 );
96+ }
97+
98+ Nan::NAN_METHOD_RETURN_TYPE osn::Module::Name (Nan::NAN_METHOD_ARGS_TYPE info)
99+ {
100+ osn::Module* module ;
101+ if (!utilv8::SafeUnwrap (info, module )) {
102+ return ;
103+ }
104+
105+ auto conn = GetConnection ();
106+ if (!conn)
107+ return ;
108+
109+ std::vector<ipc::value> response =
110+ conn->call_synchronous_helper (" Module" , " GetName" , {ipc::value (module ->moduleId )});
111+
112+ if (!ValidateResponse (response))
113+ return ;
114+
115+ info.GetReturnValue ().Set (utilv8::ToValue (response[1 ].value_str ));
116+ }
117+
118+ Nan::NAN_METHOD_RETURN_TYPE osn::Module::FileName (Nan::NAN_METHOD_ARGS_TYPE info)
119+ {
120+ osn::Module* module ;
121+ if (!utilv8::SafeUnwrap (info, module )) {
122+ return ;
123+ }
124+
125+ auto conn = GetConnection ();
126+ if (!conn)
127+ return ;
128+
129+ std::vector<ipc::value> response =
130+ conn->call_synchronous_helper (" Module" , " GetFileName" , {ipc::value (module ->moduleId )});
131+
132+ if (!ValidateResponse (response))
133+ return ;
134+
135+ info.GetReturnValue ().Set (utilv8::ToValue (response[1 ].value_str ));
136+ }
137+
138+ Nan::NAN_METHOD_RETURN_TYPE osn::Module::Description (Nan::NAN_METHOD_ARGS_TYPE info)
139+ {
140+ osn::Module* module ;
141+ if (!utilv8::SafeUnwrap (info, module )) {
142+ return ;
143+ }
144+
145+ auto conn = GetConnection ();
146+ if (!conn)
147+ return ;
148+
149+ std::vector<ipc::value> response =
150+ conn->call_synchronous_helper (" Module" , " GetDescription" , {ipc::value (module ->moduleId )});
151+
152+ if (!ValidateResponse (response))
153+ return ;
154+
155+ info.GetReturnValue ().Set (utilv8::ToValue (response[1 ].value_str ));
156+ }
157+
158+ Nan::NAN_METHOD_RETURN_TYPE osn::Module::Author (Nan::NAN_METHOD_ARGS_TYPE info)
159+ {
160+ osn::Module* module ;
161+ if (!utilv8::SafeUnwrap (info, module )) {
162+ return ;
163+ }
164+
165+ auto conn = GetConnection ();
166+ if (!conn)
167+ return ;
168+
169+ std::vector<ipc::value> response =
170+ conn->call_synchronous_helper (" Module" , " GetAuthor" , {ipc::value (module ->moduleId )});
171+
172+ if (!ValidateResponse (response))
173+ return ;
174+
175+ info.GetReturnValue ().Set (utilv8::ToValue (response[1 ].value_str ));
176+ }
177+
178+ Nan::NAN_METHOD_RETURN_TYPE osn::Module::BinaryPath (Nan::NAN_METHOD_ARGS_TYPE info)
179+ {
180+ osn::Module* module ;
181+ if (!utilv8::SafeUnwrap (info, module )) {
182+ return ;
183+ }
184+
185+ auto conn = GetConnection ();
186+ if (!conn)
187+ return ;
188+
189+ std::vector<ipc::value> response =
190+ conn->call_synchronous_helper (" Module" , " GetBinaryPath" , {ipc::value (module ->moduleId )});
191+
192+ if (!ValidateResponse (response))
193+ return ;
194+
195+ info.GetReturnValue ().Set (utilv8::ToValue (response[1 ].value_str ));
196+ }
197+
198+ Nan::NAN_METHOD_RETURN_TYPE osn::Module::DataPath (Nan::NAN_METHOD_ARGS_TYPE info)
199+ {
200+ osn::Module* module ;
201+ if (!utilv8::SafeUnwrap (info, module )) {
202+ return ;
203+ }
204+
205+ auto conn = GetConnection ();
206+ if (!conn)
207+ return ;
208+
209+ std::vector<ipc::value> response =
210+ conn->call_synchronous_helper (" Module" , " GetDataPath" , {ipc::value (module ->moduleId )});
211+
212+ if (!ValidateResponse (response))
213+ return ;
214+
215+ info.GetReturnValue ().Set (utilv8::ToValue (response[1 ].value_str ));
216+ }
0 commit comments