-
Notifications
You must be signed in to change notification settings - Fork 8
/
mod_hello_world.go
94 lines (73 loc) · 1.86 KB
/
mod_hello_world.go
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
package main
/*
#include "fs.h"
*/
import "C"
import (
"fmt"
"unsafe"
)
/****************************************/
/* START OF GLUE CODE */
/****************************************/
type Stream struct {
c_stream *C.switch_stream_handle_t
}
func (s Stream) Write(format string, a ...interface{}) {
msg := fmt.Sprintf(format, a...)
c_msg := C.CString(msg)
defer C.free(unsafe.Pointer(c_msg))
C._stream_write_function(s.c_stream, c_msg)
}
type Session struct{}
type _Log struct{}
var Log = _Log{}
func (_ _Log) Notice(format string, a ...interface{}) {
msg := fmt.Sprintf(format, a...)
c_msg := C.CString(msg)
defer C.free(unsafe.Pointer(c_msg))
C._log_on_channel(C.SWITCH_LOG_NOTICE, c_msg)
}
//export _ModuleLoad
func _ModuleLoad(module_interface *C.switch_loadable_module_interface_t) C.switch_status_t {
Load()
/*
BUG: Go shared library cannot be unloaded.
see: https://github.com/golang/go/issues/11100
*/
return C.SWITCH_STATUS_NOUNLOAD
}
//export _ModuleRuntime
func _ModuleRuntime() C.switch_status_t {
Runtime()
return C.SWITCH_STATUS_TERM
}
//export _ModuleShutdown
func _ModuleShutdown() C.switch_status_t {
Shutdown()
return C.SWITCH_STATUS_SUCCESS
}
//export _ModuleApiHandler
func _ModuleApiHandler(c_cmd *C.cchar_t, c_session *C.switch_core_session_t, c_stream *C.switch_stream_handle_t) C.switch_status_t {
cmd := C.GoString(c_cmd)
stream := Stream{c_stream}
session := Session{}
ApiHandler(cmd, session, stream)
return C.SWITCH_STATUS_SUCCESS
}
/****************************************/
/* END OF GLUE CODE */
/****************************************/
func main() {} //No Op
func Load() {
Log.Notice("Hello World!\n")
}
func Runtime() {
Log.Notice("Ruling the World!\n")
}
func Shutdown() {
Log.Notice("Good bye World!\n")
}
func ApiHandler(cmd string, session Session, stream Stream) {
stream.Write("Hello from api handler: %s\n", cmd)
}