sxutil

package module
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 4, 2021 License: Apache-2.0 Imports: 16 Imported by: 15

README

synerex_sxutil

sxutil is a Utility Library to support Synerex Server/Client development.

  • From Ver 0.5.0 we changed slightly.

The follwing is very important type for Synerex to support re-connection.

''' // SXSynerexClient is for each server from v0.5.0 type SXSynerexClient struct { ServerAddress string Client api.SynerexClient }

// SXServiceClient Wrappter Structure for synerex client type SXServiceClient struct { ClientID IDType ChannelType uint32 SXClient *SXSynerexClient ArgJson string MbusIDs []IDType mbusMutex sync.RWMutex NI *NodeServInfo } '''

Documentation

Index

Constants

View Source
const MSG_TIME_OUT = 20 // from v0.6.1 10sec -> 20sec

this is for Message Timeout for synerex server

View Source
const RECONNECT_WAIT = 5 // from v0.6.1
View Source
const WAIT_TIME = 30

Variables

View Source
var (
	Sha1Ver   string // sha1 version used to build the program
	BuildTime string // when the executable was built
	GitVer    string // git release tag
)

for git versions

Functions

func CallDeferFunctions added in v0.0.2

func CallDeferFunctions()

func CombinedSubscribeDemand added in v0.5.1

func CombinedSubscribeDemand(client *SXServiceClient, ndcb func(*SXServiceClient, *api.Demand), sscb func(*SXServiceClient, *api.Demand)) (*sync.Mutex, *bool)

Composit Subscriber for demand (ndcb = notify demand callback, sscb = selectsupply cb)

func GenerateIntID

func GenerateIntID() uint64

GenerateIntID for generate uniquie ID

func HandleSigInt added in v0.0.2

func HandleSigInt()

func InitNodeNum

func InitNodeNum(n int)

InitNodeNum for initialize NodeNum again

func MsgCountUp added in v0.3.9

func MsgCountUp()

func RegisterDeferFunction added in v0.0.2

func RegisterDeferFunction(f func())

register closing functions.

func RegisterDemandHandler added in v0.5.1

func RegisterDemandHandler(client *SXServiceClient, dh DemandHandler) (*sync.Mutex, *bool)

Register DemandHandler

func RegisterNode added in v0.2.1

func RegisterNode(nodesrv string, nm string, channels []uint32, serv *SxServerOpt) (string, error)

RegisterNode is a function to register Node with node server address

func RegisterNodeWithCmd added in v0.4.2

func RegisterNodeWithCmd(nodesrv string, nm string, channels []uint32, serv *SxServerOpt, cmd_func func(nodeapi.KeepAliveCommand, string)) (string, error)

RegisterNodeWithCmd is a function to register Node with node server address and KeepAlive Command Callback

func SetNodeStatus

func SetNodeStatus(status int32, arg string)

SetNodeStatus updates KeepAlive info to NodeServer

func SimpleSubscribeDemand added in v0.5.0

func SimpleSubscribeDemand(client *SXServiceClient, dmcb func(*SXServiceClient, *api.Demand)) (*sync.Mutex, *bool)

Simple Continuous (error free) subscriber for demand

func SimpleSubscribeSupply added in v0.5.0

func SimpleSubscribeSupply(client *SXServiceClient, spcb func(*SXServiceClient, *api.Supply)) (*sync.Mutex, *bool)

Simple Continuous (error free) subscriber for supply

func SubscribeDemand added in v0.5.0

func SubscribeDemand(client *SXServiceClient, dmcb func(*SXServiceClient, *api.Demand), mu *sync.Mutex, loopFlag *bool)

Continuous (error free) subscriber for demand

func SubscribeSupply added in v0.5.0

func SubscribeSupply(client *SXServiceClient, spcb func(*SXServiceClient, *api.Supply), mu *sync.Mutex, loopFlag *bool)

Continuous (error free) subscriber for supply

func UnRegisterNode

func UnRegisterNode()

UnRegisterNode de-registrate node id

Types

type DemandHandler added in v0.5.1

type DemandHandler interface {
	OnNotifyDemand(*SXServiceClient, *api.Demand) *SupplyOpts // if propose return proposedID
	OnSelectSupply(*SXServiceClient, *api.Demand) bool        // if confirm return true
	OnConfirmResponse(*SXServiceClient, IDType, error)        // result of confirm
}

type DemandOpts

type DemandOpts struct {
	ID     uint64
	Target uint64
	Name   string
	JSON   string
	Cdata  *api.Content
}

DemandOpts is sender options for Demand

type IDType

type IDType uint64

IDType for all ID in Synerex

type NodeServInfo added in v0.4.7

type NodeServInfo struct {
	// contains filtered or unexported fields
}

NodeservInfo is a connection info for each Node Server

func GetDefaultNodeServInfo added in v0.4.7

func GetDefaultNodeServInfo() *NodeServInfo

GetDefaultNodeServInfo returns Default NodeServ Info for sxutil

func NewNodeServInfo added in v0.4.7

func NewNodeServInfo() *NodeServInfo

NewNodeServInfo returns new NodeServ Info for sxutil

func (*NodeServInfo) GenerateIntID added in v0.4.7

func (ni *NodeServInfo) GenerateIntID() uint64

GenerateIntID for generate uniquie ID

func (*NodeServInfo) GetNodeName added in v0.4.7

func (ni *NodeServInfo) GetNodeName(n int) string

GetNodeName returns node name from node_id

func (*NodeServInfo) MsgCountUp added in v0.4.7

func (ni *NodeServInfo) MsgCountUp()

func (*NodeServInfo) NewSXServiceClient added in v0.4.7

func (ni *NodeServInfo) NewSXServiceClient(clt *SXSynerexClient, mtype uint32, argJson string) *SXServiceClient

NewSXServiceClient Creates wrapper structre SXServiceClient from SynerexClient

func (*NodeServInfo) RegisterNodeWithCmd added in v0.4.7

func (ni *NodeServInfo) RegisterNodeWithCmd(nodesrv string, nm string, channels []uint32, serv *SxServerOpt, cmd_func func(nodeapi.KeepAliveCommand, string)) (string, error)

RegisterNodeWithCmd is a function to register Node with node server address and KeepAlive Command Callback

func (*NodeServInfo) SetNodeStatus added in v0.4.7

func (ni *NodeServInfo) SetNodeStatus(status int32, arg string)

SetNodeStatus updates KeepAlive info to NodeServer

func (*NodeServInfo) UnRegisterNode added in v0.4.7

func (ni *NodeServInfo) UnRegisterNode()

UnRegisterNode de-registrate node id

type NodeState added in v0.3.12

type NodeState struct {
	ProposedSupply []api.Supply
	ProposedDemand []api.Demand
	Locked         bool
}

func NewNodeState added in v0.3.12

func NewNodeState() *NodeState

type SXServiceClient added in v0.3.3

type SXServiceClient struct {
	ClientID    IDType
	ChannelType uint32
	SXClient    *SXSynerexClient
	ArgJson     string
	MbusIDs     []IDType

	NI *NodeServInfo
	// contains filtered or unexported fields
}

SXServiceClient Wrappter Structure for synerex client

func NewSXServiceClient added in v0.3.3

func NewSXServiceClient(clt *SXSynerexClient, mtype uint32, argJson string) *SXServiceClient

NewSXServiceClient Creates wrapper structre SXServiceClient from SynerexClient

func (*SXServiceClient) CloseMbus added in v0.3.3

func (clt *SXServiceClient) CloseMbus(ctx context.Context, mbusId uint64) error

func (*SXServiceClient) Confirm added in v0.3.3

func (clt *SXServiceClient) Confirm(id IDType, pid IDType) error

Confirm sends confirm message to sender

func (*SXServiceClient) CreateMbus added in v0.4.12

func (clt *SXServiceClient) CreateMbus(ctx context.Context, opt *api.MbusOpt) (*api.Mbus, error)

from synerex_api v0.4.0

func (*SXServiceClient) GetMbusStatus added in v0.4.12

func (clt *SXServiceClient) GetMbusStatus(ctx context.Context, mb *api.Mbus) (*api.MbusState, error)

from synerex_api v0.4.0

func (*SXServiceClient) IsDemandTarget added in v0.3.3

func (clt *SXServiceClient) IsDemandTarget(dm *api.Demand, idlist []uint64) bool

IsDemandTarget is a helper function to check target

func (*SXServiceClient) IsSupplyTarget added in v0.3.3

func (clt *SXServiceClient) IsSupplyTarget(sp *api.Supply, idlist []uint64) bool

IsSupplyTarget is a helper function to check target

func (*SXServiceClient) MbusIndex added in v0.6.2

func (clt *SXServiceClient) MbusIndex(id uint64) int

func (*SXServiceClient) NotifyDemand added in v0.3.3

func (clt *SXServiceClient) NotifyDemand(dmo *DemandOpts) (uint64, error)

NotifyDemand sends Typed Demand to Server

func (*SXServiceClient) NotifySupply added in v0.3.3

func (clt *SXServiceClient) NotifySupply(smo *SupplyOpts) (uint64, error)

NotifySupply sends Typed Supply to Server

func (*SXServiceClient) ProposeDemand added in v0.5.1

func (clt *SXServiceClient) ProposeDemand(dmo *DemandOpts) uint64

ProposeDemand send proposal Demand message to server

func (*SXServiceClient) ProposeSupply added in v0.3.3

func (clt *SXServiceClient) ProposeSupply(spo *SupplyOpts) uint64

ProposeSupply send proposal Supply message to server

func (*SXServiceClient) SelectDemand added in v0.3.3

func (clt *SXServiceClient) SelectDemand(dm *api.Demand) (uint64, error)

SelectDemand send select message to server

func (*SXServiceClient) SelectSupply added in v0.3.3

func (clt *SXServiceClient) SelectSupply(sp *api.Supply) (uint64, error)

SelectSupply send select message to server

func (*SXServiceClient) SendMbusMsg added in v0.4.12

func (clt *SXServiceClient) SendMbusMsg(ctx context.Context, mbusId uint64, msg *api.MbusMsg) (uint64, error)

v0.4.1 name change

func (*SXServiceClient) SubscribeDemand added in v0.3.3

func (clt *SXServiceClient) SubscribeDemand(ctx context.Context, dmcb func(*SXServiceClient, *api.Demand)) error

SubscribeDemand Wrapper function for SXServiceClient

func (*SXServiceClient) SubscribeMbus added in v0.3.3

func (clt *SXServiceClient) SubscribeMbus(ctx context.Context, mbusId uint64, mbcb func(*SXServiceClient, *api.MbusMsg)) error

SubscribeMbus Wrapper function for SXServiceClient

func (*SXServiceClient) SubscribeSupply added in v0.3.3

func (clt *SXServiceClient) SubscribeSupply(ctx context.Context, spcb func(*SXServiceClient, *api.Supply)) error

SubscribeSupply Wrapper function for SXServiceClient

type SXSynerexClient added in v0.5.0

type SXSynerexClient struct {
	ServerAddress string
	Client        api.SynerexClient
	GrpcConn      *grpc.ClientConn
}

SXSynerexClient is for each server from v0.5.0

func GrpcConnectServer added in v0.3.4

func GrpcConnectServer(serverAddress string) *SXSynerexClient

GrpcConnectServer is a utility function for conneting gRPC server

type SupplyHandler added in v0.5.1

type SupplyHandler interface {
}

type SupplyOpts

type SupplyOpts struct {
	ID     uint64
	Target uint64
	Name   string
	JSON   string
	Cdata  *api.Content
}

SupplyOpts is sender options for Supply

type SxServerOpt added in v0.2.1

type SxServerOpt struct {
	NodeType   nodeapi.NodeType
	ServerInfo string
	ClusterId  int32
	AreaId     string
	GwInfo     string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL