refactor get public data, to be slightly easier to use on callee side
[clinton/Smoothieware.git] / src / libs / PublicDataRequest.h
CommitLineData
8293d443
JM
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
8293d443 11class PublicDataRequest {
b19aa09d 12 public:
3bfb2639
JM
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; }
8293d443 16
564cf1f0 17 virtual ~PublicDataRequest() { data= nullptr; }
8d54c34c 18
b19aa09d
JM
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]; }
8293d443 22
b19aa09d
JM
23 bool is_taken() const { return this->data_taken; }
24 void set_taken() { this->data_taken= true; }
3bfb2639 25 bool has_returned_data() const { return this->returned_data; }
564cf1f0 26 void set_data_ptr(void *d, bool flag= true) { this->data= d; returned_data= flag; }
b19aa09d 27 void* get_data_ptr(void) const { return this->data; }
8293d443 28
b19aa09d
JM
29 private:
30 uint16_t target[3];
31 void* data;
3bfb2639
JM
32 struct {
33 bool data_taken:1;
34 bool returned_data:1;
35 };
8293d443
JM
36};
37
8d54c34c 38#endif