tramservice

package
v0.0.0-...-9303afc Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2014 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MAX_ROUTE_TRAM  int = 5
	MIN_ROUTE_STOPS int = 5
)

define system limits

Variables

This section is empty.

Functions

func Logger

func Logger(message string) (err error)

debug logging facility for assignment demonstration

Types

type Client

type Client struct {
	TramObj *Tram
	// contains filtered or unexported fields
}

Client represents the functional Client and includes the open socket, requests count and new Tram object for passing to server.

func (*Client) AdvanceTram

func (c *Client) AdvanceTram() error

AdvanceTram moves the current tram to the next stop

func (*Client) AsyncAdvance

func (c *Client) AsyncAdvance()

Async wrapper

func (*Client) GetNextStop

func (c *Client) GetNextStop() (nextStop int, err error)

GetNextStop requests the next stop ID for the current route the tram/client is on. It is directional therefore previous stop and current stop IDs are passed as params.

func (*Client) Init

func (c *Client) Init(serverIP string) (err error)

Init initialises Client functionality by establishing connection to server and generating a new tram object.

func (*Client) RegisterRoute

func (c *Client) RegisterRoute(routeID int) error

RegisterRoute enables tram to be bound to a specific route this is a prerequisite for issuing any further commands to the server.

func (*Client) SetCurrentLocation

func (c *Client) SetCurrentLocation(currentStop int, previousStop int) error

SetCurrentLocation overwrites current stops in local Tram object

func (*Client) UpdateTramLocation

func (c *Client) UpdateTramLocation(nextStop int) (err error)

UpdateTramLocation notifies the server that the tram has arrived at the next tram stop.

type Message

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

Custom message encoding struct

func (*Message) Unmarshall

func (message *Message) Unmarshall() *RPCMessage

Unmarshall decodes CsvData from the Message. should return new RPCMessage with parsed values.

type MessageType

type MessageType int
const (
	Request MessageType = iota
	Reply
)

type RPCMessage

type RPCMessage struct {
	MessageType   MessageType
	TranslationId uint32
	RPCId         *uuid.UUID
	RequestID     uint32
	ProcedureID   uint32
	CsvData       string
	Status        uint32
}

func (*RPCMessage) Marshall

func (message *RPCMessage) Marshall() *Message

encode CsvData should return *Message

func (*RPCMessage) PrepReply

func (m *RPCMessage) PrepReply(in *RPCMessage)

type Record

type Record struct {
	RouteID int
	Data    *Tram
}

type Server

type Server struct {
	Clients map[string]*Record
	Routes  map[int][]*Tram
	Status  bool
}

Main server structure

func (*Server) CallBroker

func (t *Server) CallBroker(in *RPCMessage, out *RPCMessage) error

CallBroker routes calls to various functions this is not really necessary as I am exposing selected methods through RPC registry of Server struct but... for the sake of assignment here it is.

func (*Server) GetNextStop

func (t *Server) GetNextStop(in *RPCMessage, out *RPCMessage) error

GetNextStop functionality is directional

func (*Server) RegisterTram

func (t *Server) RegisterTram(in *RPCMessage, out *RPCMessage) error

RegisterTram functionality enables trams to be attached to specific routes.

func (*Server) UnregisterTram

func (t *Server) UnregisterTram(in *RPCMessage, out *RPCMessage) error

UnregisterTram removes tramID from current Clients list and the route register

func (*Server) UpdateTramLocation

func (t *Server) UpdateTramLocation(in *RPCMessage, out *RPCMessage) error

UpdateTramLocation function returns empty CSV if OK, otherwise -1

type Tram

type Tram struct {
	TramID       *uuid.UUID
	CurrentStop  int
	PreviousStop int
}

func (*Tram) FromString

func (curr *Tram) FromString(data string)

func (*Tram) ToString

func (curr *Tram) ToString() string

Jump to

Keyboard shortcuts

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