Merge remote-tracking branch 'upstream/edge' into upstream-master
[clinton/Smoothieware.git] / src / libs / PublicDataRequest.h
1 /*
2 This file is part of Smoothie (http://smoothieware.org/). The motion control part is heavily based on Grbl (https://github.com/simen/grbl).
3 Smoothie is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
4 Smoothie is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
5 You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>.
6 */
7
8 #ifndef PUBLICDATAREQUEST_H
9 #define PUBLICDATAREQUEST_H
10
11 class PublicDataRequest {
12 public:
13 PublicDataRequest(uint16_t addrcs1){ target[0]= addrcs1; target[1]= 0; target[2]= 0; data_taken= false; data= NULL; returned_data= true; }
14 PublicDataRequest(uint16_t addrcs1, uint16_t addrcs2){ target[0]= addrcs1; target[1]= addrcs2; target[2]= 0; data_taken= false; data= NULL; returned_data= true; }
15 PublicDataRequest(uint16_t addrcs1, uint16_t addrcs2, uint16_t addrcs3){ target[0]= addrcs1; target[1]= addrcs2; target[2]= addrcs3; data_taken= false; data= NULL; returned_data= true; }
16
17 virtual ~PublicDataRequest() { data= nullptr; }
18
19 bool starts_with(uint16_t addr) const { return addr == this->target[0]; }
20 bool second_element_is(uint16_t addr) const { return addr == this->target[1]; }
21 bool third_element_is(uint16_t addr) const { return addr == this->target[2]; }
22
23 bool is_taken() const { return this->data_taken; }
24 void set_taken() { this->data_taken= true; }
25 bool has_returned_data() const { return this->returned_data; }
26 void set_data_ptr(void *d, bool flag= true) { this->data= d; returned_data= flag; }
27 void* get_data_ptr(void) const { return this->data; }
28
29 private:
30 uint16_t target[3];
31 void* data;
32 struct {
33 bool data_taken:1;
34 bool returned_data:1;
35 };
36 };
37
38 #endif