Begin of json rpc API and ... making openwrt module work

Openwrt module was broken reworking all module !
This commit is contained in:
2018-09-24 17:38:17 +02:00
committed by William Petit
parent 1694111ed5
commit 6a316c53ee
21 changed files with 2128 additions and 554 deletions

View File

@ -1,29 +1,54 @@
package rpc
import (
"fmt"
"net/http"
"forge.cadoles.com/Pyxis/orion/openwrt"
"github.com/gorilla/rpc"
"github.com/gorilla/rpc/json"
)
// OrionService is the JSON-RPC API
type OrionService struct{}
// HelloArgs is the arguments expected by the Hello method
type HelloArgs struct {
Who string
type OrionService struct {
UCI *openwrt.UCI
}
// HelloResponse is the response returned from the Hello method
type HelloResponse struct {
Message string
// NewOrionService create a new OrionService !
func NewOrionService() *OrionService {
uci := openwrt.NewUCI()
return &OrionService{
UCI: uci,
}
}
// Hello is a demo RPC method fro the OrionService
func (o *OrionService) Hello(r *http.Request, args *HelloArgs, reply *HelloResponse) error {
reply.Message = fmt.Sprintf("hello %s", args.Who)
// UCIArgs argument structure for exported method OwrtListWifiDevices
type UCIArgs struct{}
// UCIResponse is the response structure for exposed method OwrtListWifiDevices
type UCIResponse struct {
Devices []map[string]string
}
// OwrtListWifiDevices offers an RPC Method to list Wifi nics in a OpenWRT device.
func (o *OrionService) OwrtListWifiDevices(r *http.Request, args *UCIArgs, reply *UCIResponse) error {
o.UCI.LoadWirelessConf()
devs := o.UCI.GetWifiDevices()
reply.Devices = devs
return nil
}
// ListIfaceArgs argument structure for exported method OwrtListWifiDevices
type ListIfaceArgs struct{}
// ListIfaceResponse is the response structure for exposed method OwrtListWifiDevices
type ListIfaceResponse struct {
Interfaces []*openwrt.UCIWirelessInterface
}
// OwrtListWifiInterfaces offers an RPC Method to list wifi interfaces in a OpenWRT device.
func (o *OrionService) OwrtListWifiInterfaces(r *http.Request, args *ListIfaceArgs, reply *ListIfaceResponse) error {
o.UCI.LoadWirelessConf()
reply.Interfaces = o.UCI.GetWifiIfaces()
return nil
}