// RegisterEOFHook registers a callback that's called when there's
// and EOF condition on the underlying channel.
168009
func (s *Server) RegisterEOFHook(h EOFHook) error {
	return s.xp.dispatcher.RegisterEOFHook(h)
}
1324179
func strconvHook(from, to reflect.Type, data reflect.Value) (reflect.Value, error) {
	if from.Kind() != reflect.String {
		return data, nil
	}

	s := data.String()
	switch to.Kind() {
	case reflect.Bool:
		b, err := strconv.ParseBool(s)
		return reflect.ValueOf(b), err
	case reflect.Float32, reflect.Float64:
		f, err := strconv.ParseFloat(s, to.Bits())
		return reflect.ValueOf(f).Convert(to), err
	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
		i, err := strconv.ParseInt(s, 10, to.Bits())
		return reflect.ValueOf(i).Convert(to), err
	case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
		u, err := strconv.ParseUint(s, 10, to.Bits())
		return reflect.ValueOf(u).Convert(to), err
	}

	return data, nil
}
641883
func (c *Connect) RegisterCloseCallback(callback CloseCallback) error {
	c.UnregisterCloseCallback()
	goCallbackId := registerCallbackId(callback)
	var err C.virError
	res := C.virConnectRegisterCloseCallbackWrapper(c.ptr, C.long(goCallbackId), &err)
	if res != 0 {
		freeCallbackId(goCallbackId)
		return makeError(&err)
	}
	connData := getConnectionData(c)
	connData.closeCallbackId = &goCallbackId
	return nil
}
703756
func (c *TowerClient) RegisterChannel(chanID lnwire.ChannelID) error {
	c.sweepPkScriptMu.Lock()
	defer c.sweepPkScriptMu.Unlock()

	// If a pkscript for this channel already exists, the channel has been
	// previously registered.
	if _, ok := c.sweepPkScripts[chanID]; ok {
		return nil
	}

	// Otherwise, generate a new sweep pkscript used to sweep funds for this
	// channel.
	pkScript, err := c.cfg.NewAddress()
	if err != nil {
		return err
	}

	// Persist the sweep pkscript so that restarts will not introduce
	// address inflation when the channel is reregistered after a restart.
	err = c.cfg.DB.AddChanPkScript(chanID, pkScript)
	if err != nil {
		return err
	}

	// Finally, cache the pkscript in our in-memory cache to avoid db
	// lookups for the remainder of the daemon's execution.
	c.sweepPkScripts[chanID] = pkScript

	return nil
}
964191
func (lr *logRegistry) AddHook(hook logrus.Hook) {
	defaultLogger.Infof("adding hook %q to registry", hook)
	lr.hooks = append(lr.hooks, hook)

	lgs := lr.ListLoggers()
	for lg := range lgs {
		logger, found := lr.Lookup(lg)
		if found {
			logger.AddHook(hook)
		}
	}
}
28568
func (logger *Logger) AddHook(hook lg.Hook) {
	mux := &sync.Mutex{}

	unsafeStd := (*unsafe.Pointer)(unsafe.Pointer(&logger.std))
	stdVal := (*lg.Logger)(atomic.LoadPointer(unsafeStd))
	old := logger.std
	mux.Lock()
	stdVal.Hooks.Add(hook)
	mux.Unlock()
	atomic.CompareAndSwapPointer(unsafeStd, unsafe.Pointer(old), unsafe.Pointer(logger.std))
}
1143227
func durationHook(from, to reflect.Type, data reflect.Value) (reflect.Value, error) {
	if from.Kind() != reflect.String || to != _typeOfDuration {
		return data, nil
	}

	d, err := time.ParseDuration(data.String())
	return reflect.ValueOf(d), err
}
1208657
func (r *Relationer) CommitHook(hi hook.Info) error {
	if r.IsImplicit() {
		panic("implicit relations must not run hooks")
	}
	if hi.Kind == hooks.RelationBroken {
		return r.die()
	}
	return r.dir.Write(hi)
}
1181821
func (p *Plugin) addHook(hookName string, hookConfig HookConfig) error {
	var lgHook logrus.Hook
	var err error

	switch hookName {
	case HookSysLog:
		address := hookConfig.Address
		if hookConfig.Address != "" {
			address = address + ":" + strconv.Itoa(hookConfig.Port)
		}
		lgHook, err = lgSyslog.NewSyslogHook(
			hookConfig.Protocol,
			address,
			syslog.LOG_INFO,
			p.ServiceLabel.GetAgentLabel(),
		)
	case HookLogStash:
		lgHook, err = logrustash.NewHook(
			hookConfig.Protocol,
			hookConfig.Address+":"+strconv.Itoa(hookConfig.Port),
			p.ServiceLabel.GetAgentLabel(),
		)
	case HookFluent:
		lgHook, err = logrus_fluent.NewWithConfig(logrus_fluent.Config{
			Host:       hookConfig.Address,
			Port:       hookConfig.Port,
			DefaultTag: p.ServiceLabel.GetAgentLabel(),
		})
	default:
		return fmt.Errorf("unsupported hook: %q", hookName)
	}
	if err != nil {
		return fmt.Errorf("creating hook for %v failed: %v", hookName, err)
	}
	// create hook
	cHook := &commonHook{Hook: lgHook}
	// fill up defined levels, or use default if not defined
	if len(hookConfig.Levels) == 0 {
		cHook.levels = []logrus.Level{logrus.PanicLevel, logrus.FatalLevel, logrus.ErrorLevel}
	} else {
		for _, level := range hookConfig.Levels {
			if lgl, err := logrus.ParseLevel(level); err == nil {
				cHook.levels = append(cHook.levels, lgl)
			} else {
				p.Log.Warnf("cannot parse hook log level %v : %v", level, err.Error())
			}
		}
	}
	// add hook to existing loggers and store it into registry for late use
	p.LogRegistry.AddHook(cHook)
	return nil
}
629697
func (opc *operationCallbacks) PrepareHook(hi hook.Info) (string, error) {
	name := string(hi.Kind)
	switch {
	case hi.Kind.IsRelation():
		var err error
		name, err = opc.u.relations.PrepareHook(hi)
		if err != nil {
			return "", err
		}
	case hi.Kind.IsStorage():
		if err := opc.u.storage.ValidateHook(hi); err != nil {
			return "", err
		}
		storageName, err := names.StorageName(hi.StorageId)
		if err != nil {
			return "", err
		}
		name = fmt.Sprintf("%s-%s", storageName, hi.Kind)
		// TODO(axw) if the agent is not installed yet,
		// set the status to "preparing storage".
	case hi.Kind == hooks.ConfigChanged:
		// TODO(axw)
		//opc.u.f.DiscardConfigEvent()
	case hi.Kind == hooks.LeaderSettingsChanged:
		// TODO(axw)
		//opc.u.f.DiscardLeaderSettingsEvent()
	}
	return name, nil
}
1201565
func RegexFilterHook(r *regexp.Regexp, useFullPath bool) FilterFileHookFunc {
	return func(info os.FileInfo, fullPath string) error {
		str := info.Name()

		if useFullPath {
			str = fullPath
		}

		// Match
		if r.MatchString(str) {
			return nil
		}

		// No match.
		return ErrSkip
	}
}
330358
func (s *PutIntentOutput) SetDialogCodeHook(v *CodeHook) *PutIntentOutput {
	s.DialogCodeHook = v
	return s
}
873235
func (client *FakeTabletManagerClient) ExecuteHook(ctx context.Context, tablet *topodatapb.Tablet, hk *hook.Hook) (*hook.HookResult, error) {
	var hr hook.HookResult
	return &hr, nil
}
1201693
func (a *Attachments) ValidateHook(hi hook.Info) error {
	storageState, err := a.storageStateForHook(hi)
	if err != nil {
		return errors.Trace(err)
	}
	return storageState.ValidateHook(hi)
}
473577
func (s *GenericAPIServer) AddPreShutdownHook(name string, hook PreShutdownHookFunc) error {
	if len(name) == 0 {
		return fmt.Errorf("missing name")
	}
	if hook == nil {
		return nil
	}

	s.preShutdownHookLock.Lock()
	defer s.preShutdownHookLock.Unlock()

	if s.preShutdownHooksCalled {
		return fmt.Errorf("unable to add %q because PreShutdownHooks have already been called", name)
	}
	if _, exists := s.preShutdownHooks[name]; exists {
		return fmt.Errorf("unable to add %q because it is already registered", name)
	}

	s.preShutdownHooks[name] = preShutdownHookEntry{hook: hook}

	return nil
}
373062
func handleHook(a HookAction, err error) {
	if err != nil {
		// TODO: handle errors
	}

	switch a {
	case HookActionContinue:
		return
	case HookActionHalt:
		panic(HookActionHalt)
	}
}
58511
func (opc *operationCallbacks) NotifyHookFailed(hook string, ctx runner.Context) {
	if opc.u.observer != nil {
		notifyHook(hook, ctx, opc.u.observer.HookFailed)
	}
}