| | |
| | | |
| | | // Reciever recv from ipc |
| | | type Reciever struct { |
| | | ctxIPC *ContextIPC |
| | | ctx context.Context |
| | | ipcURL string |
| | | chImage chan<- ImageInfo |
| | | } |
| | |
| | | } |
| | | |
| | | // 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, |
| | | } |
| | |
| | | |
| | | // 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)) |
| | | } |