Пример #1
0
/*
Create a new menu object.
Dispatches a call to ThrustCore to generate the object and return the new
TargetID in a reply.
*/
func NewMenu() *Menu {
	menu := Menu{}
	menuCreate := Command{
		Action:     "create",
		ObjectType: "menu",
	}
	menu.Sync = MenuSync{
		ReadyChan:        make(chan bool),
		DisplayedChan:    make(chan bool),
		ChildStableChan:  make(chan uint),
		TreeStableChan:   make(chan bool),
		ReadyQueue:       make([]*Command, 0),
		DisplayedQueue:   make([]*Command, 0),
		ChildStableQueue: make([]*ChildCommand, 0),
		TreeStableQueue:  make([]*Command, 0),
	}
	menu.ReplyHandlers = make(map[uint]func(reply CommandResponse, item *MenuItem))
	menu.SetSendChannel(connection.GetInputChannels())
	menu.WaitingResponses = append(menu.WaitingResponses, &menuCreate)
	dispatcher.RegisterHandler(menu.DispatchResponse)

	go menu.SendThread()
	menu.Send(&menuCreate)

	return &menu
}
Пример #2
0
/*
NewSession is a constructor that takes 3 arguments,
incognito which is a boolean, meaning dont persist session state
after close.
overrideDefaultSession which is a boolean that till tell thrust core
to try to invoke session methods from us.
path string is the path to store session data.
*/
func NewSession(incognito, overrideDefaultSession bool, path string) *Session {
	session := Session{
		CookieStore:  overrideDefaultSession,
		OffTheRecord: incognito,
		Path:         path,
	}
	if overrideDefaultSession == true {
		session.SetInvokable(*NewDummySession())
	}
	command := Command{
		Action:     "create",
		ObjectType: "session",
		Args: CommandArguments{
			CookieStore:  session.CookieStore,
			OffTheRecord: session.OffTheRecord,
			Path:         session.Path,
		},
	}
	session.SendChannel = connection.GetInputChannels()
	session.WaitingResponses = append(session.WaitingResponses, &command)
	session.Send(&command)
	dispatcher.RegisterHandler(session.DispatchResponse)
	return &session
}