视频分析2.0 多进程拆分仓库
zhangmeng
2019-05-08 ce15b43db3e60acc65ddd25de253b8577c2693aa
analysis/work/service/ipcreciever.go
@@ -10,7 +10,7 @@
// Reciever recv from ipc
type Reciever struct {
   ctxIPC  *ContextIPC
   ctx     context.Context
   ipcURL  string
   chImage chan<- ImageInfo
}
@@ -34,20 +34,10 @@
}
// NewReciever new recv
func NewReciever(url string, ch chan<- ImageInfo) *Reciever {
   ctx, cancel := context.WithCancel(context.Background())
func NewReciever(ctx context.Context, url string, ch chan<- ImageInfo) *Reciever {
   return &Reciever{
      ctxIPC:  &ContextIPC{ctx, cancel},
      ipcURL:  url,
      chImage: ch,
   }
}
// NewRecieverWithContext new recver with context
func NewRecieverWithContext(ctx context.Context, url string, ch chan<- ImageInfo) *Reciever {
   return &Reciever{
      ctxIPC:  &ContextIPC{ctx, nil},
      ctx:     ctx,
      ipcURL:  url,
      chImage: ch,
   }
@@ -62,18 +52,11 @@
// RunAsServer run a IPC server
func (r *Reciever) RunAsServer() {
   r.run(ipc.NewServer(r.ctxIPC.ctx, r.ipcURL))
   r.run(ipc.NewServer(r.ctx, r.ipcURL))
}
// RunAsClient run as a IPC client
func (r *Reciever) RunAsClient() {
   r.run(ipc.NewClient(r.ctxIPC.ctx, r.ipcURL))
}
// Stop stop reciever, run in goroutine
func (r *Reciever) Stop() {
   if r.ctxIPC.cancel != nil {
      r.ctxIPC.cancel()
   }
   r.run(ipc.NewClient(r.ctx, r.ipcURL))
}