1 /*
2  * mod_v8 for FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
3  * Copyright (C) 2013-2014, Peter Olsson <peter@olssononline.se>
4  *
5  * Version: MPL 1.1
6  *
7  * The contents of this file are subject to the Mozilla Public License Version
8  * 1.1 (the "License"); you may not use this file except in compliance with
9  * the License. You may obtain a copy of the License at
10  * http://www.mozilla.org/MPL/
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * The Original Code is mod_v8 for FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
18  *
19  * The Initial Developer of the Original Code is
20  * Peter Olsson <peter@olssononline.se>
21  * Portions created by the Initial Developer are Copyright (C)
22  * the Initial Developer. All Rights Reserved.
23  *
24  * Contributor(s):
25  * Peter Olsson <peter@olssononline.se>
26  *
27  * fsrequest.hpp -- JavaScript Request class header
28  *
29  */
30 
31 #ifndef FS_REQUEST_H
32 #define FS_REQUEST_H
33 
34 #include "javascript.hpp"
35 #include <switch.h>
36 
37 /* Macros for easier V8 callback definitions */
38 #define JS_REQUEST_GET_PROPERTY_DEF(method_name) JS_GET_PROPERTY_DEF(method_name, FSRequest)
39 #define JS_REQUEST_SET_PROPERTY_DEF(method_name) JS_SET_PROPERTY_DEF(method_name, FSRequest)
40 #define JS_REQUEST_FUNCTION_DEF(method_name) JS_FUNCTION_DEF(method_name, FSRequest)
41 #define JS_REQUEST_GET_PROPERTY_IMPL(method_name) JS_GET_PROPERTY_IMPL(method_name, FSRequest)
42 #define JS_REQUEST_SET_PROPERTY_IMPL(method_name) JS_SET_PROPERTY_IMPL(method_name, FSRequest)
43 #define JS_REQUEST_FUNCTION_IMPL(method_name) JS_FUNCTION_IMPL(method_name, FSRequest)
44 
45 class FSRequest : public JSBase
46 {
47 private:
48 	const char *_cmd;
49 	switch_stream_handle_t *_stream;
50 
51 	void Init();
52 public:
FSRequest(JSMain * owner)53 	FSRequest(JSMain *owner) : JSBase(owner) { Init(); }
FSRequest(const v8::FunctionCallbackInfo<v8::Value> & info)54 	FSRequest(const v8::FunctionCallbackInfo<v8::Value>& info) : JSBase(info) { Init(); }
55 	virtual ~FSRequest(void);
56 	virtual std::string GetJSClassName();
57 
58 	static const js_class_definition_t *GetClassDefinition();
59 
60 	void Init(const char *cmd, switch_stream_handle_t *stream);
61 
62 	/* Methods available from JavaScript */
63 	JS_REQUEST_FUNCTION_DEF(Write);
64 	JS_REQUEST_FUNCTION_DEF(GetHeader);
65 	JS_REQUEST_FUNCTION_DEF(AddHeader);
66 	JS_REQUEST_FUNCTION_DEF(DumpEnv);
67 	JS_REQUEST_GET_PROPERTY_DEF(GetProperty);
68 };
69 
70 #endif /* FS_REQUEST_H */
71 
72 /* For Emacs:
73  * Local Variables:
74  * mode:c
75  * indent-tabs-mode:t
76  * tab-width:4
77  * c-basic-offset:4
78  * End:
79  * For VIM:
80  * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
81  */
82