// RegisterCallbacks register callbacks into gorm db instance
170045
func RegisterCallbacks(db *gorm.DB) {
	if db.Callback().Create().Get("sorting:initalize_position") == nil {
		db.Callback().Create().Before("gorm:create").Register("sorting:initalize_position", initalizePosition)
	}
	if db.Callback().Delete().Get("sorting:reorder_positions") == nil {
		db.Callback().Delete().After("gorm:after_delete").Register("sorting:reorder_positions", reorderPositions)
	}
	if db.Callback().Query().Get("sorting:sort_by_position") == nil {
		db.Callback().Query().Before("gorm:query").Register("sorting:sort_by_position", beforeQuery)
	}
}
1285805
func (i *Instance) ShutdownCallbacks() []error {
	var errs []error
	for _, shutdownFunc := range i.onShutdown {
		err := shutdownFunc()
		if err != nil {
			errs = append(errs, err)
		}
	}
	for _, finalShutdownFunc := range i.onFinalShutdown {
		err := finalShutdownFunc()
		if err != nil {
			errs = append(errs, err)
		}
	}
	return errs
}
867709
func (c *VirConnection) RegisterCloseCallback(cb CloseCallback, opaque func()) error {
	c.UnregisterCloseCallback()
	context := &closeContext{
		cb: cb,
		f:  opaque,
	}
	goCallbackId := registerCallbackId(context)
	callbackPtr := unsafe.Pointer(C.closeCallback_cgo)
	res := C.virConnectRegisterCloseCallback_cgo(c.ptr, C.virConnectCloseFunc(callbackPtr), C.long(goCallbackId))
	if res != 0 {
		freeCallbackId(goCallbackId)
		return GetLastError()
	}
	connData := getConnectionData(c)
	connData.closeCallbackId = &goCallbackId
	return nil
}
153069
func (builder *SecondaryIndexQueryCommandBuilder) WithCallback(callback func([]*SecondaryIndexQueryResult) error) *SecondaryIndexQueryCommandBuilder {
	builder.callback = callback
	return builder
}
139070
func Register(name string, cb Callback) {
	if name == "" {
		panic("warmup callback name is required")
	}
	state.Lock()
	defer state.Unlock()
	state.callbacks = append(state.callbacks, callbackWithName{cb, name})
}
1032555
func RegisterValidator(name string, cb ValidatorCallback) error {
	if _, exists := validators[name]; exists {
		return ErrDuplicateValidator
	}

	validators[name] = cb
	return nil
}
1245303
func (s *Scrubber) register(cb func(*Partial), path Path, callbacks map[string]Path) {
	// do not register nil callbacks.
	if cb == nil {
		return
	}
	// subtract one to start counting from zero. This is not absolutely
	// necessary, just cosmetics.
	next := atomic.AddUint64(&s.seq, 1) - 1
	seq := strconv.FormatUint(next, 10)

	// save in scubber callbacks.
	s.Lock()
	s.callbacks[next] = cb
	s.Unlock()

	// Add to callback map to be sent to remote. Make a copy of path because it
	// is reused in caller.
	pathCopy := make(Path, len(path))
	copy(pathCopy, path)
	callbacks[seq] = pathCopy
}
1341724
func (w *drainingJobWatcher) RegisterJobs(jobs []structs.NamespacedID) {
	w.l.Lock()
	defer w.l.Unlock()

	updated := false
	for _, jns := range jobs {
		if _, ok := w.jobs[jns]; ok {
			continue
		}

		// Add the job and cancel the context
		w.logger.Trace("registering job", "job", jns)
		w.jobs[jns] = struct{}{}
		updated = true
	}

	if updated {
		w.queryCancel()

		// Create a new query context
		w.queryCtx, w.queryCancel = context.WithCancel(w.ctx)
	}
}
292540
func NewCallback(id, text string) CallbackConfig {
	return CallbackConfig{
		CallbackQueryID: id,
		Text:            text,
		ShowAlert:       false,
	}
}
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")
	}
}
40576
func mouseCallbacks(xu *xgbutil.XUtil,
	key xgbutil.MouseKey) []xgbutil.CallbackMouse {

	xu.MousebindsLck.RLock()
	defer xu.MousebindsLck.RUnlock()

	cbs := make([]xgbutil.CallbackMouse, len(xu.Mousebinds[key]))
	copy(cbs, xu.Mousebinds[key])
	return cbs
}
699551
func (mr *MockAgentProviderMockRecorder) RegisterAgents(ctx, mgr, connector, log interface{}) *gomock.Call {
	return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterAgents", reflect.TypeOf((*MockAgentProvider)(nil).RegisterAgents), ctx, mgr, connector, log)
}
827972
func RegisterGlobalCallbackIn(ctx context.Context, f Callback, metrics ...types.Metric) {
	if len(metrics) == 0 {
		panic("RegisterGlobalCallback called without any metrics")
	}

	GetState(ctx).RegisterGlobalCallbacks(GlobalCallback{f, metrics})
}
641657
func queryCallback(scope *Scope) {
	if _, skip := scope.InstanceGet("gorm:skip_query_callback"); skip {
		return
	}

	//we are only preloading relations, dont touch base model
	if _, skip := scope.InstanceGet("gorm:only_preload"); skip {
		return
	}

	defer scope.trace(NowFunc())

	var (
		isSlice, isPtr bool
		resultType     reflect.Type
		results        = scope.IndirectValue()
	)

	if orderBy, ok := scope.Get("gorm:order_by_primary_key"); ok {
		if primaryField := scope.PrimaryField(); primaryField != nil {
			scope.Search.Order(fmt.Sprintf("%v.%v %v", scope.QuotedTableName(), scope.Quote(primaryField.DBName), orderBy))
		}
	}

	if value, ok := scope.Get("gorm:query_destination"); ok {
		results = indirect(reflect.ValueOf(value))
	}

	if kind := results.Kind(); kind == reflect.Slice {
		isSlice = true
		resultType = results.Type().Elem()
		results.Set(reflect.MakeSlice(results.Type(), 0, 0))

		if resultType.Kind() == reflect.Ptr {
			isPtr = true
			resultType = resultType.Elem()
		}
	} else if kind != reflect.Struct {
		scope.Err(errors.New("unsupported destination, should be slice or struct"))
		return
	}

	scope.prepareQuerySQL()

	if !scope.HasError() {
		scope.db.RowsAffected = 0
		if str, ok := scope.Get("gorm:query_option"); ok {
			scope.SQL += addExtraSpaceIfExist(fmt.Sprint(str))
		}

		if rows, err := scope.SQLDB().Query(scope.SQL, scope.SQLVars...); scope.Err(err) == nil {
			defer rows.Close()

			columns, _ := rows.Columns()
			for rows.Next() {
				scope.db.RowsAffected++

				elem := results
				if isSlice {
					elem = reflect.New(resultType).Elem()
				}

				scope.scan(rows, columns, scope.New(elem.Addr().Interface()).Fields())

				if isSlice {
					if isPtr {
						results.Set(reflect.Append(results, elem.Addr()))
					} else {
						results.Set(reflect.Append(results, elem))
					}
				}
			}

			if err := rows.Err(); err != nil {
				scope.Err(err)
			} else if scope.db.RowsAffected == 0 && !isSlice {
				scope.Err(ErrRecordNotFound)
			}
		}
	}
}
938572
func (s *State) RegisterCallbacks(f ...Callback) {
	s.mu.Lock()
	defer s.mu.Unlock()

	s.callbacks = append(s.callbacks, f...)
}
748169
func (m *DB) RegisterMutationCallback(fn func(bool)) {
	m.dirtyL.Lock()
	m.mutationCallbacks = append(m.mutationCallbacks, fn)
	m.dirtyL.Unlock()
}
242732
func (i *Instance) ShutdownCallbacks() []error {
	var errs []error
	for _, shutdownFunc := range i.OnShutdown {
		err := shutdownFunc()
		if err != nil {
			errs = append(errs, err)
		}
	}
	for _, finalShutdownFunc := range i.OnFinalShutdown {
		err := finalShutdownFunc()
		if err != nil {
			errs = append(errs, err)
		}
	}
	return errs
}