-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoutbound.go
115 lines (103 loc) · 3.21 KB
/
outbound.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package esl
// OutboundChannel when accept a new connection from FS will derive a new channel
// Outbound pattern
// in this pattern anything could be sync because this object will be maintained by the business goroutine
// there is not thread-safe problem
type OutboundChannel struct {
*channel
// here need to cancel the registerstion of the
}
// // TODO: Execute method execute on the outbound channel
// // Loop to receive the events
// func (channel *OutboundChannel) Loop() {
// for {
// event, err := channel.recv()
// if err != nil {
// //TODO: should handle the logic with the EOF
// errorm(err)
// break
// }
// if event.Type == EslEvent {
// channel.Events <- event
// }
// if event.Type == EslReply{
// channel.reply <- event
// }
// if event.Type ==EslResponse{
// channel.response <- event
// } else {
// break
// }
// }
// }
// func (channel *OutboundChannel) syncCommand(command string) (err error) {
// command = fmt.Sprintf("%s\r\n\r\n", command)
// channel.Lock()
// err = channel.send(command)
// if err != nil {
// channel.Unlock()
// errorf("%s execute on outbound connection failed %v", command, err)
// return
// }
// channel.Unlock() // FIXME: send ordering is the same reply ordering this is the SC
// reply := <-channel.reply
// if strings.Contains(reply.Body, "-ERR"){
// return errors.New(string(reply.Body))
// }
// return
// }
// // Execute an application on this channel
// func (channel *OutboundChannel) Execute(application, arg, uuid string) (response *Event, err error) {
// var builder strings.Builder
// builder.WriteString("sendmsg")
// if uuid != "" {
// builder.WriteString(fmt.Sprintf(" %s\n", uuid))
// } else {
// builder.WriteString("\n")
// }
// builder.WriteString("call-command: execute\n")
// builder.WriteString(fmt.Sprintf("execute-app-name: %s\n", application))
// if arg != "" {
// builder.WriteString(fmt.Sprintf("execute-app-arg: %s\n", arg))
// }
// builder.WriteString("event-lock: true\n")
// channel.Lock()
// err = channel.send(builder.String())
// if err != nil {
// errorf("sendmsg failed %v", err)
// return
// }
// channel.Unlock()
// response = <-channel.reply // TODO: fix it ?
// // -ERR check logic should be done
// return
// }
// // func (channel *OutboundChannel) Execute(application, arg string) ()
// // Connect send the connect command to FS
// // Sync method
// func (channel *OutboundChannel) Connect() (err error) {
// return channel.send("command\r\n\r\n")
// }
// // Answer the inbound call from outbound channel
// func (channel *OutboundChannel) Answer() (err error) {
// respnse, err := channel.Execute("answer", "", "")
// if err != nil {
// return err
// }
// debug(respnse.Body)
// return
// }
// // Linger send the linger command to FS
// // Sync method
// // if seconds is 0 will use the default expired time
// func (channel *OutboundChannel) Linger(seconds int) (err error) {
// if seconds == 0 {
// return channel.syncCommand("linger")
// }
// return channel.syncCommand(fmt.Sprintf("linger %d", seconds))
// }
// // Nolinger send the noliner command to FS
// // Sync method
// func (channel *OutboundChannel) Nolinger() (err error) {
// return channel.syncCommand("nolinger")
// }