Skip to content

Commit d494077

Browse files
committed
fix: proper locking for widget read methods
1 parent 09573aa commit d494077

File tree

19 files changed

+124
-92
lines changed

19 files changed

+124
-92
lines changed

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"maintainer": true
1515
}
1616
],
17-
"version": "5.3.3",
17+
"version": "5.4.0",
1818
"frameworks": ["espidf", "arduino"],
1919
"platforms": "espressif32",
2020
"dependencies": [

src/gridui_version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#pragma once
22

3-
#define RB_GRIDUI_VERSION 0x050303
3+
#define RB_GRIDUI_VERSION 0x050400

src/widgets/arm.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ class Arm : public Widget {
1414

1515
public:
1616
double x() const {
17-
return data().getDouble("armX");
17+
return m_state->getDouble("armX");
1818
}
1919

2020
double y() const {
21-
return data().getDouble("armY");
21+
return m_state->getDouble("armY");
2222
}
2323
};
2424

src/widgets/bar.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,47 +18,47 @@ class Bar : public Widget {
1818
}
1919

2020
std::string color() const {
21-
return data().getString("color");
21+
return m_state->getString("color");
2222
}
2323

2424
void setFontSize(float fontSize) {
2525
m_state->set("fontSize", new rbjson::Number(fontSize));
2626
}
2727

2828
float fontSize() const {
29-
return data().getDouble("fontSize");
29+
return m_state->getDouble("fontSize");
3030
}
3131

3232
void setMin(float min) {
3333
m_state->set("min", new rbjson::Number(min));
3434
}
3535

3636
float min() const {
37-
return data().getDouble("min");
37+
return m_state->getDouble("min");
3838
}
3939

4040
void setMax(float max) {
4141
m_state->set("max", new rbjson::Number(max));
4242
}
4343

4444
float max() const {
45-
return data().getDouble("max");
45+
return m_state->getDouble("max");
4646
}
4747

4848
void setValue(float value) {
4949
m_state->set("value", new rbjson::Number(value));
5050
}
5151

5252
float value() const {
53-
return data().getDouble("value");
53+
return m_state->getDouble("value");
5454
}
5555

5656
void setShowValue(bool showValue) {
5757
m_state->set("showValue", new rbjson::Bool(showValue));
5858
}
5959

6060
bool showValue() const {
61-
return data().getBool("showValue");
61+
return m_state->getBool("showValue");
6262
}
6363
};
6464

src/widgets/button.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,47 +18,47 @@ class Button : public Widget {
1818
}
1919

2020
std::string text() const {
21-
return data().getString("text");
21+
return m_state->getString("text");
2222
}
2323

2424
void setFontSize(float fontSize) {
2525
m_state->set("fontSize", new rbjson::Number(fontSize));
2626
}
2727

2828
float fontSize() const {
29-
return data().getDouble("fontSize");
29+
return m_state->getDouble("fontSize");
3030
}
3131

3232
void setColor(const std::string& color) {
3333
m_state->set("color", new rbjson::String(color));
3434
}
3535

3636
std::string color() const {
37-
return data().getString("color");
37+
return m_state->getString("color");
3838
}
3939

4040
void setBackground(const std::string& background) {
4141
m_state->set("background", new rbjson::String(background));
4242
}
4343

4444
std::string background() const {
45-
return data().getString("background");
45+
return m_state->getString("background");
4646
}
4747

4848
void setAlign(const std::string& align) {
4949
m_state->set("align", new rbjson::String(align));
5050
}
5151

5252
std::string align() const {
53-
return data().getString("align");
53+
return m_state->getString("align");
5454
}
5555

5656
void setValign(const std::string& valign) {
5757
m_state->set("valign", new rbjson::String(valign));
5858
}
5959

6060
std::string valign() const {
61-
return data().getString("valign");
61+
return m_state->getString("valign");
6262
}
6363

6464
void setNumber(float number) {
@@ -67,15 +67,15 @@ class Button : public Widget {
6767
}
6868

6969
bool pressed() const {
70-
return data().getBool("pressed");
70+
return m_state->getBool("pressed");
7171
}
7272

7373
void setDisabled(bool disabled) {
7474
m_state->set("disabled", new rbjson::Bool(disabled));
7575
}
7676

7777
bool disabled() const {
78-
return data().getBool("disabled");
78+
return m_state->getBool("disabled");
7979
}
8080
};
8181

src/widgets/camera.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,31 @@ class Camera : public Widget {
2323
}
2424

2525
float rotation() const {
26-
return data().getDouble("rotation");
26+
return m_state->getDouble("rotation");
2727
}
2828

2929
void setClip(bool clip) {
3030
m_state->set("clip", new rbjson::Bool(clip));
3131
}
3232

3333
bool clip() const {
34-
return data().getBool("clip");
34+
return m_state->getBool("clip");
3535
}
3636

3737
void addTag(const Tag& t) {
38-
auto* tagsArray = data().getArray("tags");
38+
auto lock = m_state->uniqueStateLock();
39+
40+
auto* tagsArray = m_state->dataLocked().getArray("tags");
3941
const bool existedBefore = tagsArray != NULL;
4042
if (!existedBefore) {
4143
tagsArray = new rbjson::Array;
4244
}
4345
tagsArray->push_back(buildTagObject(t));
4446

47+
lock.unlock();
48+
4549
if (!existedBefore) {
4650
m_state->set("tags", tagsArray);
47-
}
48-
{
4951
m_state->markChanged("tags");
5052
}
5153
}

src/widgets/checkbox.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,31 @@ class Checkbox : public Widget {
1818
}
1919

2020
float fontSize() const {
21-
return data().getDouble("fontSize");
21+
return m_state->getDouble("fontSize");
2222
}
2323

2424
void setChecked(bool checked) {
2525
m_state->set("checked", new rbjson::Bool(checked));
2626
}
2727

2828
bool checked() const {
29-
return data().getBool("checked");
29+
return m_state->getBool("checked");
3030
}
3131

3232
void setColor(const std::string& color) {
3333
m_state->set("color", new rbjson::String(color));
3434
}
3535

3636
std::string color() const {
37-
return data().getString("color");
37+
return m_state->getString("color");
3838
}
3939

4040
void setText(const std::string& text) {
4141
m_state->set("text", new rbjson::String(text));
4242
}
4343

4444
std::string text() const {
45-
return data().getString("text");
45+
return m_state->getString("text");
4646
}
4747
};
4848

src/widgets/circle.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,63 +18,63 @@ class Circle : public Widget {
1818
}
1919

2020
std::string color() const {
21-
return data().getString("color");
21+
return m_state->getString("color");
2222
}
2323

2424
void setFontSize(float fontSize) {
2525
m_state->set("fontSize", new rbjson::Number(fontSize));
2626
}
2727

2828
float fontSize() const {
29-
return data().getDouble("fontSize");
29+
return m_state->getDouble("fontSize");
3030
}
3131

3232
void setMin(float min) {
3333
m_state->set("min", new rbjson::Number(min));
3434
}
3535

3636
float min() const {
37-
return data().getDouble("min");
37+
return m_state->getDouble("min");
3838
}
3939

4040
void setMax(float max) {
4141
m_state->set("max", new rbjson::Number(max));
4242
}
4343

4444
float max() const {
45-
return data().getDouble("max");
45+
return m_state->getDouble("max");
4646
}
4747

4848
void setLineWidth(float lineWidth) {
4949
m_state->set("lineWidth", new rbjson::Number(lineWidth));
5050
}
5151

5252
float lineWidth() const {
53-
return data().getDouble("lineWidth");
53+
return m_state->getDouble("lineWidth");
5454
}
5555

5656
void setValueStart(float valueStart) {
5757
m_state->set("valueStart", new rbjson::Number(valueStart));
5858
}
5959

6060
float valueStart() const {
61-
return data().getDouble("valueStart");
61+
return m_state->getDouble("valueStart");
6262
}
6363

6464
void setValue(float value) {
6565
m_state->set("value", new rbjson::Number(value));
6666
}
6767

6868
float value() const {
69-
return data().getDouble("value");
69+
return m_state->getDouble("value");
7070
}
7171

7272
void setShowValue(bool showValue) {
7373
m_state->set("showValue", new rbjson::Bool(showValue));
7474
}
7575

7676
bool showValue() const {
77-
return data().getBool("showValue");
77+
return m_state->getBool("showValue");
7878
}
7979
};
8080

src/widgets/input.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,31 @@ class Input : public Widget {
1818
}
1919

2020
std::string text() const {
21-
return data().getString("text");
21+
return m_state->getString("text");
2222
}
2323

2424
void setColor(const std::string& color) {
2525
m_state->set("color", new rbjson::String(color));
2626
}
2727

2828
std::string color() const {
29-
return data().getString("color");
29+
return m_state->getString("color");
3030
}
3131

3232
void setType(const std::string& type) {
3333
m_state->set("type", new rbjson::String(type));
3434
}
3535

3636
std::string type() const {
37-
return data().getString("type");
37+
return m_state->getString("type");
3838
}
3939

4040
void setDisabled(bool disabled) {
4141
m_state->set("disabled", new rbjson::Bool(disabled));
4242
}
4343

4444
bool disabled() const {
45-
return data().getBool("disabled");
45+
return m_state->getBool("disabled");
4646
}
4747
};
4848

src/widgets/joystick.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,31 @@ class Joystick : public Widget {
1818
}
1919

2020
std::string color() const {
21-
return data().getString("color");
21+
return m_state->getString("color");
2222
}
2323

2424
void setKeys(const std::string& keys) {
2525
m_state->set("keys", new rbjson::String(keys));
2626
}
2727

2828
std::string keys() const {
29-
return data().getString("keys");
29+
return m_state->getString("keys");
3030
}
3131

3232
void setText(const std::string& text) {
3333
m_state->set("text", new rbjson::String(text));
3434
}
3535

3636
std::string text() const {
37-
return data().getString("text");
37+
return m_state->getString("text");
3838
}
3939

4040
int32_t x() const {
41-
return data().getInt("jx");
41+
return m_state->getInt("jx");
4242
}
4343

4444
int32_t y() const {
45-
return data().getInt("jy");
45+
return m_state->getInt("jy");
4646
}
4747
};
4848

0 commit comments

Comments
 (0)