// wrapStreamRegistrationCallback wraps the given callback to dispatch on the correct stream type.
424989
func wrapStreamRegistrationCallback(reg streamRegistrationCallback) streamRegistrationCallback {
	if reg == nil {
		return reg
	}
	return func(desc *logpb.LogStreamDescriptor) bundler.StreamChunkCallback {
		cb := reg(desc)
		switch desc.StreamType {
		case logpb.StreamType_TEXT:
			return buffered_callback.GetWrappedTextCallback(cb)
		case logpb.StreamType_DATAGRAM:
			return buffered_callback.GetWrappedDatagramCallback(cb)
		default:
			return cb
		}
	}
}
245629
func (s *Scrubber) RemoveCallback(id uint64) {
	s.Lock()
	delete(s.callbacks, id)
	s.Unlock()
}
248425
func RegisterIntGaugeCallback(name string, tgs Tags, cb IntGaugeCallback) {
	id := atomic.AddUint32(curIntCbID, 1) - 1

	if id >= maxNumCallbacks {
		panic("Too many callbacks")
	}

	intcallbacks[id] = cb
	intcbnames[id] = name

	tgs = copyTags(tgs)
	tgs[TagMetricType] = MetricTypeGauge
	intcbtags[id] = tgs
}
947907
func (c *Client) RegisterStream(ctx context.Context, in *s.RegisterStreamRequest, opts ...grpc.CallOption) (
	*s.RegisterStreamResponse, error) {

	resp, err := c.bundleRPC(ctx, opts, &s.BatchRequest_Entry{
		Value: &s.BatchRequest_Entry_RegisterStream{RegisterStream: in},
	})
	if err != nil {
		return nil, err
	}

	return resp.GetRegisterStream(), nil
}
878525
func (m *Middleware) CallStream(ctx context.Context, request *transport.StreamRequest, out transport.StreamOutbound) (*transport.ClientStream, error) {
	call := m.graph.begin(ctx, transport.Streaming, _directionOutbound, request.Meta.ToRequest())
	clientStream, err := out.CallStream(ctx, request)
	// TODO(pedge): wrap the *transport.ClientStream?
	call.End(err)
	return clientStream, err
}
646156
func (b *Bundle) SetRecompilationCallback(c func(*template.Registry)) *Bundle {
	b.recompilationCallback = c
	return b
}
207589
func logCallback(a *C.utp_callback_arguments) C.uint64 {
	Logger.Printf("libutp: %s", C.GoString((*C.char)(unsafe.Pointer(a.buf))))
	return 0
}
753732
func compilerCallback(errorLevel C.int, filename *C.char, linenumber C.int, message *C.char, userData unsafe.Pointer) {
	c := callbackData.Get(userData).(*Compiler)
	msg := CompilerMessage{
		Filename: C.GoString(filename),
		Line:     int(linenumber),
		Text:     C.GoString(message),
	}
	switch errorLevel {
	case C.YARA_ERROR_LEVEL_ERROR:
		c.Errors = append(c.Errors, msg)
	case C.YARA_ERROR_LEVEL_WARNING:
		c.Warnings = append(c.Warnings, msg)
	}
}
457131
func (c *Client) runCallback(callback func(*dnode.Partial), args *dnode.Partial) {
	// Do not panic no matter what.
	defer func() {
		if err := recover(); err != nil {
			c.LocalKite.Log.Warning("Error in calling the callback function : %v", err)
		}
	}()

	// Call the callback function.
	callback(args)
}
753751
func (d *dispatcher) RegisterFunc(c StreamType, h HandlerFunc) {
	d.handlers[c] = &basicHandler{h}
}
476577
func streamCallback(inputBuffer, outputBuffer unsafe.Pointer, frames C.ulong, timeInfo *C.PaStreamCallbackTimeInfo, statusFlags C.PaStreamCallbackFlags, userData unsafe.Pointer) {
	defer func() {
		// Don't let PortAudio silently swallow panics.
		if x := recover(); x != nil {
			buf := make([]byte, 1<<10)
			for runtime.Stack(buf, true) == len(buf) {
				buf = make([]byte, 2*len(buf))
			}
			fmt.Fprintf(os.Stderr, "panic in portaudio stream callback: %s\n\n%s", x, buf)
			os.Exit(2)
		}
	}()

	s := getStream(uintptr(userData))
	s.timeInfo = StreamCallbackTimeInfo{duration(timeInfo.inputBufferAdcTime), duration(timeInfo.currentTime), duration(timeInfo.outputBufferDacTime)}
	s.flags = StreamCallbackFlags(statusFlags)
	updateBuffer(s.in, uintptr(inputBuffer), s.inParams, int(frames))
	updateBuffer(s.out, uintptr(outputBuffer), s.outParams, int(frames))
	s.callback.Call(s.args)
}
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")
	}
}
1368244
func (em *EventMeter) RegisterLatencyCallback(f LatencyCallbackFunc) {
	em.mtx.Lock()
	defer em.mtx.Unlock()
	em.latencyCallback = f
}
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")
	}
}
1153575
func includeCallback(name, filename, namespace *C.char, userData unsafe.Pointer) *C.char {
	callbackFunc := callbackData.Get(userData).(CompilerIncludeFunc)
	if buf := callbackFunc(
		C.GoString(name), C.GoString(filename), C.GoString(namespace),
	); buf != nil {
		ptr := C.calloc(1, C.size_t(len(buf)+1))
		if ptr == nil {
			return nil
		}
		outbuf := make([]byte, 0)
		hdr := (*reflect.SliceHeader)(unsafe.Pointer(&outbuf))
		hdr.Data, hdr.Len = uintptr(ptr), len(buf)+1
		copy(outbuf, buf)
		return (*C.char)(ptr)
	}
	return nil
}
510743
func (p *Provider) handleCallback(rw http.ResponseWriter, req *http.Request, _ router.Params) error {
	// oauth handshake
	code := req.FormValue("code")
	accessToken, err := p.Config.Exchange(oauth2.NoContext, code)
	if err != nil {
		return errors.Wrap(err)
	}
	var state string
	encState := req.FormValue("state")
	if encState != "" {
		stateByte, err := base64.StdEncoding.DecodeString(encState)
		if err != nil {
			return errors.New("error decoding state: %s", err)
		}
		state = string(stateByte)
	}
	err = p.PostCallback(req, rw, accessToken, state)
	if err != nil {
		return errors.Wrap(err)
	}
	return nil
}
30848
func (c *TokenController) LinkCallback(ctx *app.LinkCallbackTokenContext) error {
	redirectLocation, err := c.app.LinkService().Callback(ctx, ctx.RequestData, ctx.State, ctx.Code)
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, err)
	}
	ctx.ResponseData.Header().Set("Location", redirectLocation)
	return ctx.TemporaryRedirect()
}