// parseCallbacks parses the message's "callbacks" field and prepares
// callback functions in "arguments" field.
195036
func ParseCallbacks(msg *Message, sender func(id uint64, args []interface{}) error) error {
	// Parse callbacks field and create callback functions.
	for methodID, path := range msg.Callbacks {
		id, err := strconv.ParseUint(methodID, 10, 64)
		if err != nil {
			return err
		}

		f := func(args ...interface{}) error { return sender(id, args) }
		spec := CallbackSpec{path, Function{functionReceived(f)}}
		msg.Arguments.CallbackSpecs = append(msg.Arguments.CallbackSpecs, spec)
	}

	return nil
}
361217
func connErrorCallback(goCallbackId int, err C.virErrorPtr) {
	ctx := getCallbackId(goCallbackId)
	switch cctx := ctx.(type) {
	case *errorContext:
		cctx.cb(newError(err), cctx.f)
	default:
		panic("Inappropriate callback type called")
	}
}
1311739
func (this *Future) addCallback(callback interface{}, t callbackType) {
	if callback == nil {
		return
	}
	if (t == CALLBACK_DONE) ||
		(t == CALLBACK_FAIL) ||
		(t == CALLBACK_ALWAYS) {
		if _, ok := callback.(func(v interface{})); !ok {
			panic(errors.New("Callback function spec must be func(v interface{})"))
		}
	} else if t == CALLBACK_CANCEL {
		if _, ok := callback.(func()); !ok {
			panic(errors.New("Callback function spec must be func()"))
		}
	}

	for {
		v := this.loadVal()
		r := v.r
		if r == nil {
			newVal := *v
			switch t {
			case CALLBACK_DONE:
				newVal.dones = append(newVal.dones, callback.(func(v interface{})))
			case CALLBACK_FAIL:
				newVal.fails = append(newVal.fails, callback.(func(v interface{})))
			case CALLBACK_ALWAYS:
				newVal.always = append(newVal.always, callback.(func(v interface{})))
			case CALLBACK_CANCEL:
				newVal.cancels = append(newVal.cancels, callback.(func()))
			}

			//use CAS to ensure that the state of Future is not changed,
			//if the state is changed, will retry CAS operation.
			if atomic.CompareAndSwapPointer(&this.val, unsafe.Pointer(v), unsafe.Pointer(&newVal)) {
				break
			}
		} else {
			if (t == CALLBACK_DONE && r.Typ == RESULT_SUCCESS) ||
				(t == CALLBACK_FAIL && r.Typ == RESULT_FAILURE) ||
				(t == CALLBACK_ALWAYS && r.Typ != RESULT_CANCELLED) {
				callbackFunc := callback.(func(v interface{}))
				callbackFunc(r.Result)
			} else if t == CALLBACK_CANCEL && r.Typ == RESULT_CANCELLED {
				callbackFunc := callback.(func())
				callbackFunc()
			}
			break
		}
	}
}
60540
func (p *Parser) parseCall(name string) (*Call, error) {
	name = strings.ToLower(name)

	// Parse first function argument if one exists.
	var args []Expr
	re, err := p.parseRegex()
	if err != nil {
		return nil, err
	} else if re != nil {
		args = append(args, re)
	} else {
		// If there's a right paren then just return immediately.
		if tok, _, _ := p.Scan(); tok == RPAREN {
			return &Call{Name: name}, nil
		}
		p.Unscan()

		arg, err := p.ParseExpr()
		if err != nil {
			return nil, err
		}
		args = append(args, arg)
	}

	// Parse additional function arguments if there is a comma.
	for {
		// If there's not a comma, stop parsing arguments.
		if tok, _, _ := p.ScanIgnoreWhitespace(); tok != COMMA {
			p.Unscan()
			break
		}

		re, err := p.parseRegex()
		if err != nil {
			return nil, err
		} else if re != nil {
			args = append(args, re)
			continue
		}

		// Parse an expression argument.
		arg, err := p.ParseExpr()
		if err != nil {
			return nil, err
		}
		args = append(args, arg)
	}

	// There should be a right parentheses at the end.
	if tok, pos, lit := p.Scan(); tok != RPAREN {
		return nil, newParseError(tokstr(tok, lit), []string{")"}, pos)
	}

	return &Call{Name: name, Args: args}, nil
}
1278201
func (s *UserPoolClientType) SetCallbackURLs(v []*string) *UserPoolClientType {
	s.CallbackURLs = v
	return s
}
1255911
func (reqRes *ReqRes) SetCallback(cb func(res *types.Response)) {
	reqRes.mtx.Lock()

	if reqRes.done {
		reqRes.mtx.Unlock()
		cb(reqRes.Response)
		return
	}

	reqRes.cb = cb
	reqRes.mtx.Unlock()
}
405309
func (twilio *Twilio) CallWithApplicationCallbacks(from, to, applicationSid string) (*VoiceResponse, *Exception, error) {
	formValues := url.Values{}
	formValues.Set("From", from)
	formValues.Set("To", to)
	formValues.Set("ApplicationSid", applicationSid)

	return twilio.voicePost(formValues)
}
316617
func (manager *configManager) execNodeCallbacks(f CallbackNodeConfigFunc, data *data) {
	config := new(NodeConfig)
	if err := json.Unmarshal(data.Value, config); err != nil {
		logrus.Error(err)
		return
	}

	f(config)
}
815369
func ParseArgs(args []string) (string, []string, bool) {

	if len(args) == 0 {
		return "", []string{}, false
	}

	pluginName := ""
	pluginArgs := []string{}
	for idx, arg := range args {

		if strings.Contains(arg, bitrisePluginPrefix) {
			pluginSplits := strings.Split(arg, ":")

			if len(pluginSplits) != 2 {
				return "", []string{}, false
			}

			pluginName = pluginSplits[1]
			if len(args) > idx {
				pluginArgs = args[idx+1 : len(args)]
			}
			return pluginName, pluginArgs, true
		}
	}

	return "", []string{}, false
}
745019
func closeCallback(conn C.virConnectPtr, reason int, goCallbackId int) {
	ctx := getCallbackId(goCallbackId)
	switch cctx := ctx.(type) {
	case *closeContext:
		cctx.cb(VirConnection{ptr: conn}, reason, cctx.f)
	default:
		panic("Inappropriate callback type called")
	}
}
918592
func eventHandleCallback(watch int, fd int, events int, callbackID int) {
	callbackFunc := getCallbackId(callbackID)

	callback, ok := callbackFunc.(EventHandleCallback)
	if !ok {
		panic("Incorrect event handle callback data")
	}

	callback(watch, fd, (EventHandleType)(events))
}
245629
func (s *Scrubber) RemoveCallback(id uint64) {
	s.Lock()
	delete(s.callbacks, id)
	s.Unlock()
}
623360
func (m *Message) SendCallback(fn CallbackFunc, arg interface{}) error {
	s, err := newSocket()
	if err != nil {
		return err
	}
	defer s.free()

	if errno := C.genl_connect(s.nls); errno != 0 {
		return &Error{errno, "failed to connect to netlink"}
	}
	defer C.nl_close(s.nls)

	cbArg := &callbackArg{fn: fn, arg: arg}
	cbID := registerCallback(cbArg)
	defer unregisterCallback(cbArg)

	if errno := C._nl_socket_modify_cb(s.nls, C.NL_CB_VALID, C.NL_CB_CUSTOM, (C.nl_recvmsg_msg_cb_t)(unsafe.Pointer(C.callbackGateway)), C.uintptr_t(cbID)); errno != 0 {
		return &Error{errno, "failed to modify callback"}
	}
	// nl_send_auto_complete returns number of bytes sent or a negative
	// errno on failure.
	if errno := C.nl_send_auto_complete(s.nls, m.nlm); errno < 0 {
		return &Error{errno, "failed to send netlink message"}
	}
	if errno := C.nl_recvmsgs_default(s.nls); errno != 0 {
		return &Error{errno, "failed to receive messages"}
	}
	return nil
}
529390
func (manager *configManager) execClusterCallbacks(f CallbackClusterConfigFunc, data *data) {
	config := new(ClusterConfig)
	if err := json.Unmarshal(data.Value, config); err != nil {
		logrus.Error(err)
		return
	}

	f(config)
}
1095518
func LogCallback(c context.Context, opname string) Callback {
	return func(err error, delay time.Duration) {
		logging.Fields{
			logging.ErrorKey: err,
			"opname":         opname,
			"delay":          delay,
		}.Warningf(c, "operation failed transiently")
	}
}
311464
func RegisterCallbacks(db *gorm.DB) {
	db.Callback().Update().Before("gorm:before_update").Register("media_library:save_and_crop", saveAndCropImage(false))
	db.Callback().Create().After("gorm:after_create").Register("media_library:save_and_crop", saveAndCropImage(true))
}
499797
func NewCallbacksOrReferences(in interface{}, context *compiler.Context) (*CallbacksOrReferences, error) {
	errors := make([]error, 0)
	x := &CallbacksOrReferences{}
	m, ok := compiler.UnpackMap(in)
	if !ok {
		message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
		errors = append(errors, compiler.NewError(context, message))
	} else {
		// repeated NamedCallbackOrReference additional_properties = 1;
		// MAP: CallbackOrReference
		x.AdditionalProperties = make([]*NamedCallbackOrReference, 0)
		for _, item := range m {
			k, ok := compiler.StringValue(item.Key)
			if ok {
				v := item.Value
				pair := &NamedCallbackOrReference{}
				pair.Name = k
				var err error
				pair.Value, err = NewCallbackOrReference(v, compiler.NewContext(k, context))
				if err != nil {
					errors = append(errors, err)
				}
				x.AdditionalProperties = append(x.AdditionalProperties, pair)
			}
		}
	}
	return x, compiler.NewErrorGroupOrNil(errors)
}