Ardour  8.12
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 #ifndef __ardour_worker_h__
22 #define __ardour_worker_h__
23 
24 #include <stdint.h>
25 
26 #include "pbd/pthread_utils.h"
27 #include "pbd/ringbuffer.h"
28 #include "pbd/semutils.h"
29 
31 
32 namespace ARDOUR {
33 
34 class Worker;
35 
40 public:
41  virtual ~Workee() {}
42 
46  virtual int work(Worker& worker, uint32_t size, const void* data) = 0;
47 
51  virtual int work_response(uint32_t size, const void* data) = 0;
52 };
53 
62 {
63 public:
64  Worker(Workee* workee, uint32_t ring_size, bool threaded=true);
66 
71  bool schedule(uint32_t size, const void* data);
72 
77  bool respond(uint32_t size, const void* data);
78 
83 
92  void set_synchronous(bool synchronous) { _synchronous = synchronous; }
93 
94 private:
95  void run();
106 
110  uint8_t* _response;
113  bool _exit;
115 };
116 
117 } // namespace ARDOUR
118 
119 #endif /* __ardour_worker_h__ */
virtual int work(Worker &worker, uint32_t size, const void *data)=0
virtual ~Workee()
Definition: worker.h:41
virtual int work_response(uint32_t size, const void *data)=0
bool _synchronous
Definition: worker.h:114
PBD::RingBuffer< uint8_t > * _requests
Definition: worker.h:108
PBD::RingBuffer< uint8_t > * _responses
Definition: worker.h:109
Worker(Workee *workee, uint32_t ring_size, bool threaded=true)
uint8_t * _response
Definition: worker.h:110
void set_synchronous(bool synchronous)
Definition: worker.h:92
bool schedule(uint32_t size, const void *data)
PBD::Thread * _thread
Definition: worker.h:112
PBD::Semaphore _sem
Definition: worker.h:111
bool _exit
Definition: worker.h:113
void emit_responses()
bool verify_message_completeness(PBD::RingBuffer< uint8_t > *rb)
Workee * _workee
Definition: worker.h:107
bool respond(uint32_t size, const void *data)
#define LIBARDOUR_API