예제 #1
0
파일: menu.go 프로젝트: dzyk/dcoin-go
/*
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
파일: session.go 프로젝트: dzyk/dcoin-go
/*
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
}