diff options
author | Yorhel <git@yorhel.nl> | 2012-04-17 16:13:34 +0200 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2012-04-17 16:13:34 +0200 |
commit | 7b6252e2fdec1d48a21f2ea4db6ca547424d5b48 (patch) | |
tree | b3110bd30f20691b361fd997e8e888287a53b51d | |
parent | 09e9ea4b0dd049d2e528e858a3c75263fa1e01f5 (diff) |
rpc: Let RegRPC return a list of registrations
Useful when dynamically (un)registering blocks of methods.
-rw-r--r-- | rpc.go | 11 | ||||
-rw-r--r-- | rpc_test.go | 6 |
2 files changed, 10 insertions, 7 deletions
@@ -39,10 +39,11 @@ import "reflect" // captured by any previous arguments) will be passed through to the last // argument. // -// Returns the number of patters registered. +// Returns a list of all *Registrations made, or nil of nothing has been registered. // // TODO: Examples are required to really understand the use of this method. -func (s *Session) RegRPC(obj interface{}, f func(string) Tuple) int { +func (s *Session) RegRPC(obj interface{}, f func(string) Tuple) []*Registration { + var lst []*Registration objv := reflect.ValueOf(obj) objt := objv.Type() num := 0 @@ -72,10 +73,12 @@ func (s *Session) RegRPC(obj interface{}, f func(string) Tuple) int { pat = append(pat, El(nil)) } // Generate callback and register - s.Registert(willReply, pat).Callback(regRPCGenCallback(mt, mv, offset, willReply)) + r := s.Registert(willReply, pat) + r.Callback(regRPCGenCallback(mt, mv, offset, willReply)) + lst = append(lst, r) num++ } - return num + return lst } // Should be mostly the reverse of El(). Returns the zero value if the type is diff --git a/rpc_test.go b/rpc_test.go index b26751b..75347fd 100644 --- a/rpc_test.go +++ b/rpc_test.go @@ -88,14 +88,14 @@ func TestRPC(tst *testing.T) { ses := node.Session() obj := &sT{tst: tst, ses: ses} - n := ses.RegRPC(obj, func(s string) Tuple { + lst := ses.RegRPC(obj, func(s string) Tuple { if strings.HasPrefix(s, "Export") { return Tup("prefix", 1, strings.ToLower(s[6:])) } return nil }) - if n != 4 { - tst.Fatalf("Number of exported methods is %d, expected %d", n, 4) + if len(lst) != 4 { + tst.Fatalf("Number of exported methods is %d, expected %d", len(lst), 4) } go func() { |