github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/protocol/keybase1/reachability.go (about)

     1  // Auto-generated to Go types and interfaces using avdl-compiler v1.4.10 (https://github.com/keybase/node-avdl-compiler)
     2  //   Input file: avdl/keybase1/reachability.avdl
     3  
     4  package keybase1
     5  
     6  import (
     7  	"fmt"
     8  	"github.com/keybase/go-framed-msgpack-rpc/rpc"
     9  	context "golang.org/x/net/context"
    10  	"time"
    11  )
    12  
    13  type Reachable int
    14  
    15  const (
    16  	Reachable_UNKNOWN Reachable = 0
    17  	Reachable_YES     Reachable = 1
    18  	Reachable_NO      Reachable = 2
    19  )
    20  
    21  func (o Reachable) DeepCopy() Reachable { return o }
    22  
    23  var ReachableMap = map[string]Reachable{
    24  	"UNKNOWN": 0,
    25  	"YES":     1,
    26  	"NO":      2,
    27  }
    28  
    29  var ReachableRevMap = map[Reachable]string{
    30  	0: "UNKNOWN",
    31  	1: "YES",
    32  	2: "NO",
    33  }
    34  
    35  func (e Reachable) String() string {
    36  	if v, ok := ReachableRevMap[e]; ok {
    37  		return v
    38  	}
    39  	return fmt.Sprintf("%v", int(e))
    40  }
    41  
    42  type Reachability struct {
    43  	Reachable Reachable `codec:"reachable" json:"reachable"`
    44  }
    45  
    46  func (o Reachability) DeepCopy() Reachability {
    47  	return Reachability{
    48  		Reachable: o.Reachable.DeepCopy(),
    49  	}
    50  }
    51  
    52  type ReachabilityChangedArg struct {
    53  	Reachability Reachability `codec:"reachability" json:"reachability"`
    54  }
    55  
    56  type StartReachabilityArg struct {
    57  }
    58  
    59  type CheckReachabilityArg struct {
    60  }
    61  
    62  type ReachabilityInterface interface {
    63  	ReachabilityChanged(context.Context, Reachability) error
    64  	// Start reachability checks and return current status, which
    65  	// may be cached.
    66  	StartReachability(context.Context) (Reachability, error)
    67  	// Performs a reachability check. This is not a cached response.
    68  	CheckReachability(context.Context) (Reachability, error)
    69  }
    70  
    71  func ReachabilityProtocol(i ReachabilityInterface) rpc.Protocol {
    72  	return rpc.Protocol{
    73  		Name: "keybase.1.reachability",
    74  		Methods: map[string]rpc.ServeHandlerDescription{
    75  			"reachabilityChanged": {
    76  				MakeArg: func() interface{} {
    77  					var ret [1]ReachabilityChangedArg
    78  					return &ret
    79  				},
    80  				Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
    81  					typedArgs, ok := args.(*[1]ReachabilityChangedArg)
    82  					if !ok {
    83  						err = rpc.NewTypeError((*[1]ReachabilityChangedArg)(nil), args)
    84  						return
    85  					}
    86  					err = i.ReachabilityChanged(ctx, typedArgs[0].Reachability)
    87  					return
    88  				},
    89  			},
    90  			"startReachability": {
    91  				MakeArg: func() interface{} {
    92  					var ret [1]StartReachabilityArg
    93  					return &ret
    94  				},
    95  				Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
    96  					ret, err = i.StartReachability(ctx)
    97  					return
    98  				},
    99  			},
   100  			"checkReachability": {
   101  				MakeArg: func() interface{} {
   102  					var ret [1]CheckReachabilityArg
   103  					return &ret
   104  				},
   105  				Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
   106  					ret, err = i.CheckReachability(ctx)
   107  					return
   108  				},
   109  			},
   110  		},
   111  	}
   112  }
   113  
   114  type ReachabilityClient struct {
   115  	Cli rpc.GenericClient
   116  }
   117  
   118  func (c ReachabilityClient) ReachabilityChanged(ctx context.Context, reachability Reachability) (err error) {
   119  	__arg := ReachabilityChangedArg{Reachability: reachability}
   120  	err = c.Cli.Notify(ctx, "keybase.1.reachability.reachabilityChanged", []interface{}{__arg}, 0*time.Millisecond)
   121  	return
   122  }
   123  
   124  // Start reachability checks and return current status, which
   125  // may be cached.
   126  func (c ReachabilityClient) StartReachability(ctx context.Context) (res Reachability, err error) {
   127  	err = c.Cli.Call(ctx, "keybase.1.reachability.startReachability", []interface{}{StartReachabilityArg{}}, &res, 0*time.Millisecond)
   128  	return
   129  }
   130  
   131  // Performs a reachability check. This is not a cached response.
   132  func (c ReachabilityClient) CheckReachability(ctx context.Context) (res Reachability, err error) {
   133  	err = c.Cli.Call(ctx, "keybase.1.reachability.checkReachability", []interface{}{CheckReachabilityArg{}}, &res, 0*time.Millisecond)
   134  	return
   135  }