ivy

package module
v0.0.0-...-bc026ab Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2021 License: GPL-3.0 Imports: 17 Imported by: 0

README

Ivy: a lightweight software bus

Ivy is a lightweight software bus for quick-prototyping protocols. It allows applications to broadcast information through text messages, with a subscription mechanism based on regular expressions.

This is the native go implementation. A lot of materials, including libraries for many languages are available from the Ivy Home Page.

For now, only the following functions from the standard API are available in this implementation:

  • IvyInit
  • IvyStart
  • IvyStop
  • IvyMainLoop
  • IvyBindMsg
  • IvyUnbindMsg
  • IvySendMsg
  • IvyBindDirectMsg
  • IvySendDirectMsg

Moreover, only IPv4 is supported for now (no IPv6 support).

Example

package main

import (
    "fmt"
    "log"

    "github.com/mroy31/ivy-go"
)

var busId = "127.255.255.255:2010"

func OnMsg(agent ivy.IvyApplication, params []string) {
    fmt.Println("Receive msg: " + params[0])
}

func main() {
    if err := ivy.IvyInit("ivy-go-example", "Ready", 0, nil, nil); err != nil {
        log.Fatalf("Unable to init ivy bus: %v", err)
    }

    ivy.IvyBindMsg(OnMsg, "(.*)")

    if err := ivy.IvyStart(busId); err != nil {
        log.Fatalf("Unable to start ivy bus: %v", err)
    }

    err := ivy.IvyMainLoop()
    if err != nil {
        log.Fatalf("IvyMainLoop ends with an error: %v", err)
    }
}

A more complete example is available in the example directory.

License

GNU General Public License v3.0 or later

See COPYING to see the full text.

Documentation

Index

Constants

View Source
const (
	ARG_START = "\002"
	ARG_END   = "\003"
)
View Source
const (
	PROTOCOL_VERSION = 3
)

Variables

This section is empty.

Functions

func GetLogger

func GetLogger() *logrus.Logger

func IvyBindDirectMsg

func IvyBindDirectMsg(cb IvyBindDirectCallback) error

func IvyBindMsg

func IvyBindMsg(cb IvyBindCallback, re string) (int, error)

func IvyInit

func IvyInit(agentName, readyMsg string, mainLoop int, onCnxFunc, onDieFunc IvyAppCallback) error

func IvyMainLoop

func IvyMainLoop() error

func IvySendDirectMsg

func IvySendDirectMsg(agentId int, numId int, msg string) error

func IvySendMsg

func IvySendMsg(msg string) error

func IvyStart

func IvyStart(busId string) error

func IvyStop

func IvyStop() error

func IvyUnbindMsg

func IvyUnbindMsg(subId int) (string, error)

func SetLogger

func SetLogger(w io.Writer, level logrus.Level)

Types

type AgentState

type AgentState int
const (
	AGENT_NOT_INIT AgentState = iota
	AGENT_INIT_PROGRESS
	AGENT_INIT
)

type AgentT

type AgentT struct {
	ID              int
	AgentID         string
	Name            string
	SubcriptionLock *sync.Mutex
	Subscriptions   []SubscriptionT
	MsgCh           chan MessageT
	Conn            net.Conn
	State           AgentState
	Bus             *BusT
	Logger          *logrus.Entry
}

func (*AgentT) Close

func (c *AgentT) Close()

func (*AgentT) Init

func (c *AgentT) Init() error

func (*AgentT) SendDelSubscription

func (c *AgentT) SendDelSubscription(id int)

func (*AgentT) SendDirectMsg

func (c *AgentT) SendDirectMsg(numId int, msg string)

func (*AgentT) SendMsg

func (c *AgentT) SendMsg(msg string)

func (*AgentT) SendSubscription

func (c *AgentT) SendSubscription(id int, re string)

type BusState

type BusState int
const (
	CLOSE BusState = iota
	INIT
	STARTED
)

type BusT

type BusT struct {
	ID              string
	Name            string
	ReadyMsg        string
	OnCnxFunc       IvyAppCallback
	OnDieFunc       IvyAppCallback
	DirectMsgCb     IvyBindDirectCallback
	Conn            net.Listener
	WaitCh          chan error
	UDPConn         *net.UDPConn
	UDPWaitCh       chan error
	Agents          []*AgentT
	SubcriptionLock *sync.Mutex
	Subscriptions   []SubscriptionT
	Logger          *logrus.Entry
}

func (*BusT) BindMsg

func (b *BusT) BindMsg(re string, cb IvyBindCallback) (int, error)

func (*BusT) ConnectToClient

func (b *BusT) ConnectToClient(addr string, port int, appName, appId string) error

func (*BusT) GetAgent

func (b *BusT) GetAgent(agentId int) *AgentT

func (*BusT) GetBusPort

func (b *BusT) GetBusPort() int

func (*BusT) SendMessage

func (b *BusT) SendMessage(msg string)

func (*BusT) Start

func (b *BusT) Start(busId string) error

func (*BusT) Stop

func (b *BusT) Stop() error

func (*BusT) UnbindMsg

func (b *BusT) UnbindMsg(subId int) (string, error)

type IvyAppCallback

type IvyAppCallback func(agent IvyApplication)

type IvyApplication

type IvyApplication struct {
	ID      int
	Name    string
	AgentId string
}

func IvyGetApplicationByName

func IvyGetApplicationByName(appName string) (IvyApplication, error)

func IvyGetApplicationList

func IvyGetApplicationList() ([]IvyApplication, error)

type IvyBindCallback

type IvyBindCallback func(agent IvyApplication, params []string)

type IvyBindDirectCallback

type IvyBindDirectCallback func(agent IvyApplication, numId int, msg string)

type IvySubscription

type IvySubscription struct {
	ID     int
	Regexp string
}

func IvyGetApplicationMessages

func IvyGetApplicationMessages(agentId int) ([]IvySubscription, error)

type MessageT

type MessageT struct {
	Type   MsgType
	NumId  int
	Params []string
}

type MsgType

type MsgType int
const (
	BYE MsgType = iota
	ADD_REGEXP
	MSG
	ERROR
	DEL_REGEXP
	END_REGEXP
	START_REGEXP
	DIRECT_MSG
	DIE
	PING
	PONG
)

type SubscriptionT

type SubscriptionT struct {
	Id   int
	Text string
	Re   *regexp.Regexp
	Cb   IvyBindCallback
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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