WIP: JSONRPC server refactoring
Some checks reported errors
Pyxis/orion/feature%2Fjsonrpc-next Something is wrong with the build of this commit
Pyxis/orion/pipeline/head Something is wrong with the build of this commit
LaCanne/orion/pipeline/head Something is wrong with the build of this commit

This commit is contained in:
2019-02-12 10:17:06 +01:00
parent 0f0213c326
commit 713ca17c62
69 changed files with 13073 additions and 2728 deletions

View File

@ -0,0 +1,32 @@
package jsonrpc
import (
"net/http"
"forge.cadoles.com/Cadoles/owrt"
"github.com/davecgh/go-spew/spew"
)
type ScanWifiArgs struct{}
type ScanWifiReply struct {
AccessPoints []*owrt.WifiCell
}
// ScanWifi starts a WiFi scan and returns available access points
func (o *OrionService) ScanWifi(r *http.Request, args *ScanWifiArgs, reply *ScanWifiReply) error {
o.UCI.LoadWirelessConf()
ifaces := o.UCI.GetWifiIfaces()
reply.AccessPoints = make([]*owrt.WifiCell, 0)
for _, iface := range ifaces {
scanner := owrt.NewWifiScanner(iface.Name)
cells := scanner.Scan()
spew.Dump(iface, cells)
reply.AccessPoints = append(reply.AccessPoints, cells...)
}
return nil
}

View File

@ -1,8 +1,9 @@
package jsonrpc
import (
"forge.cadoles.com/wpetit/goweb/service"
"github.com/gorilla/rpc"
"forge.cadoles.com/wpetit/goweb/service"
"github.com/pkg/errors"
)
@ -10,17 +11,14 @@ const ServiceName service.Name = "jsonrpc"
// From retrieves the JSONRPC service in the given container or panic
func From(container *service.Container) (*rpc.Server, error) {
service, err := container.Service(ServiceName)
if err != nil {
return nil, errors.Wrapf(err, "error while retrieving '%s' service", ServiceName)
}
jsonRPCService, ok := service.(*rpc.Server)
if !ok {
return nil, errors.Errorf("retrieved service is not a valid '%s' service", ServiceName)
}
return jsonRPCService, nil
}

View File

@ -1,6 +1,17 @@
POST http://192.168.100.1:8888/rpc HTTP/1.1
content-type: application/json
{
"id": 0,
"method": "Orion.OwrtListWifiDevices",
"params": []
}
###
POST http://192.168.100.1:8888/rpc HTTP/1.1
content-type: application/json
{
"id": 1,
"method": "Orion.OwrtCreateWifiInterface",