Ardour  9.0-pre0-582-g084a23a80d
worker.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2013 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2012-2016 David Robillard <d@drobilla.net>
4  * Copyright (C) 2012-2017 Robin Gareus <robin@gareus.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #pragma once
22 
23 #include <stdint.h>
24 
25 #include "pbd/pthread_utils.h"
26 #include "pbd/ringbuffer.h"
27 #include "pbd/semutils.h"
28 
30 
31 namespace ARDOUR {
32 
33 class Worker;
34 
39 public:
40  virtual ~Workee() {}
41 
45  virtual int work(Worker& worker, uint32_t size, const void* data) = 0;
46 
50  virtual int work_response(uint32_t size, const void* data) = 0;
51 };
52 
61 {
62 public:
63  Worker(Workee* workee, uint32_t ring_size, bool threaded=true);
65 
70  bool schedule(uint32_t size, const void* data);
71 
76  bool respond(uint32_t size, const void* data);
77 
82 
91  void set_synchronous(bool synchronous) { _synchronous = synchronous; }
92 
93 private:
94  void run();
105 
109  uint8_t* _response;
112  bool _exit;
114 };
115 
116 } // namespace ARDOUR
117 
virtual int work(Worker &worker, uint32_t size, const void *data)=0
virtual ~Workee()
Definition: worker.h:40
virtual int work_response(uint32_t size, const void *data)=0
bool _synchronous
Definition: worker.h:113
PBD::RingBuffer< uint8_t > * _requests
Definition: worker.h:107
PBD::RingBuffer< uint8_t > * _responses
Definition: worker.h:108
Worker(Workee *workee, uint32_t ring_size, bool threaded=true)
uint8_t * _response
Definition: worker.h:109
void set_synchronous(bool synchronous)
Definition: worker.h:91
bool schedule(uint32_t size, const void *data)
PBD::Thread * _thread
Definition: worker.h:111
PBD::Semaphore _sem
Definition: worker.h:110
bool _exit
Definition: worker.h:112
void emit_responses()
bool verify_message_completeness(PBD::RingBuffer< uint8_t > *rb)
Workee * _workee
Definition: worker.h:106
bool respond(uint32_t size, const void *data)
#define LIBARDOUR_API