added console commands and ShowSubscribers method

This commit is contained in:
Radu Ioan Fericean
2015-07-02 09:59:26 +03:00
parent 9c9465e1fc
commit 54fa1476d9
5 changed files with 269 additions and 3 deletions

64
console/publish.go Normal file
View File

@@ -0,0 +1,64 @@
/*
Rating system designed to be used in VoIP Carriers World
Copyright (C) 2012-2015 ITsysCOM
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package console
import "github.com/cgrates/cgrates/engine"
func init() {
c := &CmdPublish{
name: "publish",
rpcMethod: "PubSubV1.Publish",
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
type CmdPublish struct {
name string
rpcMethod string
rpcParams *engine.PublishInfo
*CommandExecuter
}
func (self *CmdPublish) Name() string {
return self.name
}
func (self *CmdPublish) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdPublish) RpcParams(ptr bool) interface{} {
if self.rpcParams == nil {
self.rpcParams = &engine.PublishInfo{}
}
if ptr {
return self.rpcParams
}
return *self.rpcParams
}
func (self *CmdPublish) PostprocessRpcParams() error {
return nil
}
func (self *CmdPublish) RpcResult() interface{} {
var s string
return &s
}

View File

@@ -0,0 +1,64 @@
/*
Rating system designed to be used in VoIP Carriers World
Copyright (C) 2012-2015 ITsysCOM
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package console
import "time"
func init() {
c := &CmdShowSubscribers{
name: "show_subscribers",
rpcMethod: "PubSubV1.ShowSubscribers",
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
type CmdShowSubscribers struct {
name string
rpcMethod string
rpcParams *StringWrapper
*CommandExecuter
}
func (self *CmdShowSubscribers) Name() string {
return self.name
}
func (self *CmdShowSubscribers) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdShowSubscribers) RpcParams(ptr bool) interface{} {
if self.rpcParams == nil {
self.rpcParams = &StringWrapper{}
}
if ptr {
return self.rpcParams
}
return *self.rpcParams
}
func (self *CmdShowSubscribers) PostprocessRpcParams() error {
return nil
}
func (self *CmdShowSubscribers) RpcResult() interface{} {
var s map[string]map[string]time.Time
return &s
}

64
console/subscribe.go Normal file
View File

@@ -0,0 +1,64 @@
/*
Rating system designed to be used in VoIP Carriers World
Copyright (C) 2012-2015 ITsysCOM
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package console
import "github.com/cgrates/cgrates/engine"
func init() {
c := &CmdSubscribe{
name: "subscribe",
rpcMethod: "PubSubV1.Subscribe",
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
type CmdSubscribe struct {
name string
rpcMethod string
rpcParams *engine.SubscribeInfo
*CommandExecuter
}
func (self *CmdSubscribe) Name() string {
return self.name
}
func (self *CmdSubscribe) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdSubscribe) RpcParams(ptr bool) interface{} {
if self.rpcParams == nil {
self.rpcParams = &engine.SubscribeInfo{}
}
if ptr {
return self.rpcParams
}
return *self.rpcParams
}
func (self *CmdSubscribe) PostprocessRpcParams() error {
return nil
}
func (self *CmdSubscribe) RpcResult() interface{} {
var s string
return &s
}

64
console/unsubscribe.go Normal file
View File

@@ -0,0 +1,64 @@
/*
Rating system designed to be used in VoIP Carriers World
Copyright (C) 2012-2015 ITsysCOM
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package console
import "github.com/cgrates/cgrates/engine"
func init() {
c := &CmdUnsubscribe{
name: "unsubscribe",
rpcMethod: "PubSubV1.Unsubscribe",
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
type CmdUnsubscribe struct {
name string
rpcMethod string
rpcParams *engine.SubscribeInfo
*CommandExecuter
}
func (self *CmdUnsubscribe) Name() string {
return self.name
}
func (self *CmdUnsubscribe) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdUnsubscribe) RpcParams(ptr bool) interface{} {
if self.rpcParams == nil {
self.rpcParams = &engine.SubscribeInfo{}
}
if ptr {
return self.rpcParams
}
return *self.rpcParams
}
func (self *CmdUnsubscribe) PostprocessRpcParams() error {
return nil
}
func (self *CmdUnsubscribe) RpcResult() interface{} {
var s string
return &s
}

View File

@@ -26,6 +26,7 @@ type PublisherSubscriber interface {
Subscribe(SubscribeInfo, *string) error
Unsubscribe(SubscribeInfo, *string) error
Publish(PublishInfo, *string) error
ShowSubscribers(string, *map[string]map[string]time.Time) error
}
type PubSub struct {
@@ -138,6 +139,11 @@ func (ps *PubSub) Publish(pi PublishInfo, reply *string) error {
return nil
}
func (ps *PubSub) ShowSubscribers(in string, out *map[string]map[string]time.Time) error {
*out = ps.subscribers
return nil
}
type ProxyPubSub struct {
Client *rpcclient.RpcClient
}
@@ -151,11 +157,15 @@ func NewProxyPubSub(addr string, reconnects int) (*ProxyPubSub, error) {
}
func (ps *ProxyPubSub) Subscribe(si SubscribeInfo, reply *string) error {
return ps.Client.Call("PubSub.Subscribe", si, reply)
return ps.Client.Call("PubSubV1.Subscribe", si, reply)
}
func (ps *ProxyPubSub) Unsubscribe(si SubscribeInfo, reply *string) error {
return ps.Client.Call("PubSub.Unsubscribe", si, reply)
return ps.Client.Call("PubSubV1.Unsubscribe", si, reply)
}
func (ps *ProxyPubSub) Publish(pi PublishInfo, reply *string) error {
return ps.Client.Call("PubSub.Publish", pi, reply)
return ps.Client.Call("PubSubV1.Publish", pi, reply)
}
func (ps *ProxyPubSub) ShowSubscribers(in string, reply *map[string]map[string]time.Time) error {
return ps.Client.Call("PubSubV1.ShowSubscribers", in, reply)
}