Example #1
0
func ProcRecordResult(
	handler *coreprocessing.Handler,
	inIns *coreprocessing.CoreInstruction,
	outIns *coreprocessing.CoreInstruction) []*coreprocessing.CoreInstruction {
	//
	var result []*coreprocessing.CoreInstruction
	if answer, _ := outIns.GetAnswer(); (*answer).Error.Code == 0 {
		if srcCmd, hasCmd := inIns.GetCommand(); hasCmd {
			rpcManager := coreprocessing.NewRpcServerManager()
			taskId := (*srcCmd).Params.Task
			if targetCidPtr := rpcManager.ResultDirectionDict.Get(taskId); targetCidPtr != nil {
				// check client group
				if handler.StateCheker.ClientInGroup(*targetCidPtr, connectionsupport.GroupConnectionWsClient) {
					cmd := transport.NewCommandWithParams(
						0, "result", transport.MethodParams{
							Cid:  *targetCidPtr,
							Task: taskId,
							Json: (*srcCmd).Params.Json})
					clientIns := coreprocessing.NewCoreInstruction(coreprocessing.TypeInstructionSetResult)
					clientIns.SetCommand(cmd)
					result = make([]*coreprocessing.CoreInstruction, 1)
					result[0] = clientIns
				} else {
					rpcManager.ResultBufferDict.Set(taskId, (*srcCmd).Params.Json)
				}
			} else {
				rllogger.Outputf(rllogger.LogError, "Processing pass for: %s", srcCmd)
			}
		}
	}
	return result
}
Example #2
0
func ProcCallServerMethod(
	handler *coreprocessing.Handler,
	inIns *coreprocessing.CoreInstruction,
	outIns *coreprocessing.CoreInstruction) []*coreprocessing.CoreInstruction {
	//
	var result []*coreprocessing.CoreInstruction

	if answer, exists := outIns.GetAnswer(); exists {
		if (*answer).Error.Code == 0 {
			if srcCmd, hasCmd := inIns.GetCommand(); hasCmd {
				rpcData := RpcAnswerData{}
				// little overhead - parse JSON
				if loadErr := json.Unmarshal([]byte((*answer).Result), &rpcData); loadErr == nil {
					srcParams := (*srcCmd).Params
					srcParams.Task = rpcData.Task
					// replace cid
					srcParams.Cid = rpcData.Cid
					newCmd := transport.NewCommandWithParams(0, (*srcCmd).Method, srcParams)
					resultIns := coreprocessing.NewCoreInstruction(coreprocessing.TypeInstructionExecute)
					resultIns.SetCommand(newCmd)
					result = []*coreprocessing.CoreInstruction{resultIns}
				} else {
					rllogger.Outputf(
						rllogger.LogError,
						"Answer from ProcRouteRpc has incorrect data format, from: %s",
						inIns.Cid)
				}
			} else {
				rllogger.Outputf(rllogger.LogError, "Answer lost in ProcRouteRpc! from: %s", inIns.Cid)
			}
		}
	} else {
		rllogger.Outputf(rllogger.LogError, "Answer lost in ProcRouteRpc! from: %s", inIns.Cid)
	}
	return result
}