示例#1
0
func sendCallMethod(
	msg *CoreMsg,
	serverBusyAccounting *helpers.ServerBusyAccounting,
	serverMethods *helpers.ServerMethods) ([]*ServerCmd, error) {
	//
	var err error
	var cmd, servCmd *ServerCmd
	cid := (*msg).Cid
	method := (*msg).Method
	if serverMethods.IsPublic(method) {
		if freeCid, exists := serverMethods.SearchFree(method, serverBusyAccounting); exists {
			rand := helpers.NewSystemRandom()
			task := rand.CreateTaskId()
			taskInfo := fmt.Sprintf("{\"task\": \"%s\"}", task)
			cmd = NewServerDataCmd(CmdOk, cid, &taskInfo)
			execDataInst := execData{
				Task:   task,
				Data:   string((*msg).Data),
				Method: method}
			if data, dumpErr := dumps(execDataInst, false); dumpErr != nil {
				err = dumpErr
			} else {
				servCmd = NewServerDataCmd(CmdCallMethod, freeCid, &data)
				rllogger.Outputf(rllogger.LogDebug, "method '%s' -> %s", method, freeCid)
			}
		} else {
			cmd = NewServerCmd(CmdWaitFree, cid)
		}
	} else {
		cmd = NewServerCmd(CmdProblem, cid)
		err = errors.New(fmt.Sprintf("Method '%s' not found", method))
	}
	return []*ServerCmd{cmd, servCmd}, err
}
示例#2
0
func registrationPublicMethods(
	msg *CoreMsg,
	serverBusyAccounting *helpers.ServerBusyAccounting,
	serverMethods *helpers.ServerMethods) ([]*ServerCmd, error) {
	//
	var err error
	var cmd *ServerCmd
	cid := (*msg).Cid
	data := (*msg).Data
	if errReg := serverMethods.FillFromMsgData(cid, &data); errReg != nil {
		rllogger.Outputf(
			rllogger.LogError,
			"client %s failed methods registration with error: %s",
			cid, errReg)
		err = errReg
		cmd = NewServerExitCmd()
	} else {
		rllogger.Outputf(rllogger.LogInfo, "methods of server %s: %s", cid, data)
		cmd = NewServerCmd(CmdWaitCommand, cid)
	}
	return []*ServerCmd{cmd}, err
}