Commit 77a99cc6 authored by Max Kellermann's avatar Max Kellermann

CommandListBuilder: rename attributes

parent fb337418
...@@ -25,23 +25,23 @@ ...@@ -25,23 +25,23 @@
void void
CommandListBuilder::Reset() CommandListBuilder::Reset()
{ {
for (GSList *tmp = cmd_list; tmp != NULL; tmp = g_slist_next(tmp)) for (GSList *tmp = list; tmp != NULL; tmp = g_slist_next(tmp))
g_free(tmp->data); g_free(tmp->data);
g_slist_free(cmd_list); g_slist_free(list);
cmd_list = nullptr; list = nullptr;
cmd_list_OK = -1; mode = Mode::DISABLED;
} }
bool bool
CommandListBuilder::Add(const char *cmd) CommandListBuilder::Add(const char *cmd)
{ {
size_t len = strlen(cmd) + 1; size_t len = strlen(cmd) + 1;
cmd_list_size += len; size += len;
if (cmd_list_size > client_max_command_list_size) if (size > client_max_command_list_size)
return false; return false;
cmd_list = g_slist_prepend(cmd_list, g_strdup(cmd)); list = g_slist_prepend(list, g_strdup(cmd));
return true; return true;
} }
...@@ -25,23 +25,38 @@ ...@@ -25,23 +25,38 @@
class CommandListBuilder { class CommandListBuilder {
/** /**
* for when in list mode * print OK after each command execution
*/ */
GSList *cmd_list; enum class Mode {
/**
* Not active.
*/
DISABLED = -1,
/**
* Enabled in normal list mode.
*/
ENABLED = false,
/**
* Enabled in "list_OK" mode.
*/
OK = true,
} mode;
/** /**
* print OK after each command execution * for when in list mode
*/ */
int cmd_list_OK; GSList *list;
/** /**
* mem cmd_list consumes * Memory consumed by the list.
*/ */
size_t cmd_list_size; size_t size;
public: public:
CommandListBuilder() CommandListBuilder()
:cmd_list(nullptr), cmd_list_OK(-1), cmd_list_size(0) {} :mode(Mode::DISABLED), list(nullptr), size(0) {}
~CommandListBuilder() { ~CommandListBuilder() {
Reset(); Reset();
} }
...@@ -50,9 +65,7 @@ public: ...@@ -50,9 +65,7 @@ public:
* Is a command list currently being built? * Is a command list currently being built?
*/ */
bool IsActive() const { bool IsActive() const {
assert(cmd_list_OK >= -1 && cmd_list_OK <= 1); return mode != Mode::DISABLED;
return cmd_list_OK >= 0;
} }
/** /**
...@@ -61,7 +74,7 @@ public: ...@@ -61,7 +74,7 @@ public:
bool IsOKMode() const { bool IsOKMode() const {
assert(IsActive()); assert(IsActive());
return (bool)cmd_list_OK; return (bool)mode;
} }
/** /**
...@@ -73,10 +86,10 @@ public: ...@@ -73,10 +86,10 @@ public:
* Begin building a command list. * Begin building a command list.
*/ */
void Begin(bool ok) { void Begin(bool ok) {
assert(cmd_list == nullptr); assert(list == nullptr);
assert(cmd_list_OK == -1); assert(mode == Mode::DISABLED);
cmd_list_OK = (int)ok; mode = (Mode)ok;
} }
/** /**
...@@ -93,7 +106,7 @@ public: ...@@ -93,7 +106,7 @@ public:
/* for scalability reasons, we have prepended each new /* for scalability reasons, we have prepended each new
command; now we have to reverse it to restore the command; now we have to reverse it to restore the
correct order */ correct order */
return cmd_list = g_slist_reverse(cmd_list); return list = g_slist_reverse(list);
} }
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment