Skip to content

Commit

Permalink
modify CMD2_ANY_VALUE_V
Browse files Browse the repository at this point in the history
  • Loading branch information
Young-Flash committed Sep 12, 2022
1 parent f90d2bb commit 7f04318
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 23 deletions.
10 changes: 7 additions & 3 deletions include/command_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,16 @@ cleanup_commands();
key, command_base_call_value<rpc::target_type>, slot, "i:i", "") \
} while (0) \

#define CMD2_ANY_VALUE_V(key, slot) \
CMD2_A_FUNCTION(key, \
#define CMD2_ANY_VALUE_V(key, slot, is_readonly) \
do { \
if (is_readonly) rpc::readonly_command.insert(key); \
CMD2_A_FUNCTION(key, \
command_base_call_value<rpc::target_type>, \
object_convert_void(slot), \
"i:i", \
"")
"") \
} while (0) \

#define CMD2_ANY_VALUE_KB(key, slot) \
CMD2_A_FUNCTION(key, \
command_base_call_value_kb<rpc::target_type>, \
Expand Down
16 changes: 8 additions & 8 deletions src/command_local.cc
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ initialize_command_local() {
}, true);

CMD2_ANY_VALUE_V("system.umask.set",
[](const auto&, const auto& mode) { return umask(mode); });
[](const auto&, const auto& mode) { return umask(mode); }, false);

CMD2_VAR_BOOL("system.daemon", false);

Expand All @@ -281,7 +281,7 @@ initialize_command_local() {
CMD2_ANY_VALUE_V("pieces.sync.always_safe.set",
[chunkManager](const auto&, const auto& state) {
return chunkManager->set_safe_sync(state);
});
}, false);
CMD2_ANY("pieces.sync.safe_free_diskspace",
[chunkManager](const auto&, const auto&) {
return chunkManager->safe_free_diskspace();
Expand All @@ -292,15 +292,15 @@ initialize_command_local() {
CMD2_ANY_VALUE_V("pieces.sync.timeout.set",
[chunkManager](const auto&, const auto& seconds) {
return chunkManager->set_timeout_sync(seconds);
});
}, false);
CMD2_ANY("pieces.sync.timeout_safe",
[chunkManager](const auto&, const auto&) {
return chunkManager->timeout_safe_sync();
}, true);
CMD2_ANY_VALUE_V("pieces.sync.timeout_safe.set",
[chunkManager](const auto&, const auto& seconds) {
return chunkManager->set_timeout_safe_sync(seconds);
});
}, false);
CMD2_ANY("pieces.sync.queue_size", [chunkManager](const auto&, const auto&) {
return chunkManager->sync_queue_size();
}, true);
Expand All @@ -311,21 +311,21 @@ initialize_command_local() {
CMD2_ANY_VALUE_V("pieces.preload.type.set",
[chunkManager](const auto&, const auto& t) {
return chunkManager->set_preload_type(t);
});
}, false);
CMD2_ANY("pieces.preload.min_size", [chunkManager](const auto&, const auto&) {
return chunkManager->preload_min_size();
}, true);
CMD2_ANY_VALUE_V("pieces.preload.min_size.set",
[chunkManager](const auto&, const auto& bytes) {
return chunkManager->set_preload_min_size(bytes);
});
}, false);
CMD2_ANY("pieces.preload.min_rate", [chunkManager](const auto&, const auto&) {
return chunkManager->preload_required_rate();
}, true);
CMD2_ANY_VALUE_V("pieces.preload.min_rate.set",
[chunkManager](const auto&, const auto& bytes) {
return chunkManager->set_preload_required_rate(bytes);
});
}, false);

CMD2_ANY("pieces.memory.current", [chunkManager](const auto&, const auto&) {
return chunkManager->memory_usage();
Expand All @@ -344,7 +344,7 @@ initialize_command_local() {
CMD2_ANY_VALUE_V("pieces.memory.max.set",
[chunkManager](const auto&, const auto& bytes) {
return chunkManager->set_max_memory_usage(bytes);
});
}, false);
CMD2_ANY("pieces.stats_preloaded", [chunkManager](const auto&, const auto&) {
return chunkManager->stats_preloaded();
}, true);
Expand Down
18 changes: 9 additions & 9 deletions src/command_network.cc
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ initialize_command_network() {
[cm](const auto&, const auto&) { return cm->listen_backlog(); }, true);
CMD2_ANY_VALUE_V(
"network.listen.backlog.set",
[cm](const auto&, const auto& v) { return cm->set_listen_backlog(v); });
[cm](const auto&, const auto& v) { return cm->set_listen_backlog(v); }, false);

CMD2_VAR_BOOL("protocol.pex", true);
CMD2_ANY_LIST("protocol.encryption.set", [](const auto&, const auto& args) {
Expand Down Expand Up @@ -303,7 +303,7 @@ initialize_command_network() {
CMD2_ANY_VALUE_V("network.http.dns_cache_timeout.set",
[httpStack](const auto&, const auto& timeout) {
return httpStack->set_dns_timeout(timeout);
});
}, false);
CMD2_ANY("network.http.current_open", [httpStack](const auto&, const auto&) {
return httpStack->active();
}, true);
Expand All @@ -313,7 +313,7 @@ initialize_command_network() {
CMD2_ANY_VALUE_V("network.http.max_open.set",
[httpStack](const auto&, const auto& a) {
return httpStack->set_max_active(a);
});
}, false);
CMD2_ANY("network.http.proxy_address", [httpStack](const auto&, const auto&) {
return httpStack->http_proxy();
}, true);
Expand All @@ -328,28 +328,28 @@ initialize_command_network() {
CMD2_ANY_VALUE_V("network.http.ssl_verify_host.set",
[httpStack](const auto&, const auto& v) {
return httpStack->set_ssl_verify_host(v);
});
}, false);
CMD2_ANY("network.http.ssl_verify_peer",
[httpStack](const auto&, const auto&) {
return httpStack->ssl_verify_peer();
}, true);
CMD2_ANY_VALUE_V("network.http.ssl_verify_peer.set",
[httpStack](const auto&, const auto& v) {
return httpStack->set_ssl_verify_peer(v);
});
}, false);

CMD2_ANY("network.send_buffer.size",
[cm](const auto&, const auto&) { return cm->send_buffer_size(); }, true);
CMD2_ANY_VALUE_V(
"network.send_buffer.size.set",
[cm](const auto&, const auto& v) { return cm->set_send_buffer_size(v); });
[cm](const auto&, const auto& v) { return cm->set_send_buffer_size(v); }, false);
CMD2_ANY("network.receive_buffer.size", [cm](const auto&, const auto&) {
return cm->receive_buffer_size();
}, true);
CMD2_ANY_VALUE_V("network.receive_buffer.size.set",
[cm](const auto&, const auto& v) {
return cm->set_receive_buffer_size(v);
});
}, false);
CMD2_ANY_STRING("network.tos.set",
[](const auto&, const auto& arg) { return apply_tos(arg); }, false);

Expand Down Expand Up @@ -384,7 +384,7 @@ initialize_command_network() {
CMD2_ANY_VALUE_V("network.max_open_files.set",
[fileManager](const auto&, const auto& v) {
return fileManager->set_max_open_files(v);
});
}, false);
CMD2_ANY("network.total_handshakes", [](const auto&, const auto&) {
return torrent::total_handshakes();
}, true);
Expand All @@ -394,7 +394,7 @@ initialize_command_network() {
[cm](const auto&, const auto&) { return cm->max_size(); }, true);
CMD2_ANY_VALUE_V(
"network.max_open_sockets.set",
[cm](const auto&, const auto& v) { return cm->set_max_size(v); });
[cm](const auto&, const auto& v) { return cm->set_max_size(v); }, false);

CMD2_ANY_STRING("network.scgi.open_port", [](const auto&, const auto& arg) {
return apply_scgi(arg, 1);
Expand Down
4 changes: 2 additions & 2 deletions src/command_throttle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ initialize_command_throttle() {
CMD2_ANY_VALUE_V("throttle.global_up.max_rate.set",
[](const auto&, const auto& throttle) {
return control->ui()->set_up_throttle_i64(throttle);
});
}, false);
CMD2_ANY_VALUE_KB("throttle.global_up.max_rate.set_kb",
[](const auto&, const auto& throttle) {
return control->ui()->set_up_throttle_i64(throttle);
Expand All @@ -246,7 +246,7 @@ initialize_command_throttle() {
CMD2_ANY_VALUE_V("throttle.global_down.max_rate.set",
[](const auto&, const auto& throttle) {
return control->ui()->set_down_throttle_i64(throttle);
});
}, false);
CMD2_ANY_VALUE_KB("throttle.global_down.max_rate.set_kb",
[](const auto&, const auto& throttle) {
return control->ui()->set_down_throttle_i64(throttle);
Expand Down
2 changes: 1 addition & 1 deletion src/command_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ initialize_command_ui() {
CMD2_ANY_VALUE_V("ui.input.history.size.set",
[](const auto&, const auto& size) {
return control->ui()->set_input_history_size(size);
});
}, false);
CMD2_ANY_V("ui.input.history.clear", [](const auto&, const auto&) {
return control->ui()->clear_input_history();
}, false);
Expand Down

0 comments on commit 7f04318

Please sign in to comment.