mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2026-04-01 10:49:55 +03:00
style: apply clang-format and enforce left pointer alignment
This commit is contained in:
@@ -28,20 +28,18 @@ namespace Metrics {
|
||||
|
||||
Event& Batch::add_feature_event() { return add_event(feature_evt_name); }
|
||||
void Batch::add_remove_feature_event(const char* name, bool active) {
|
||||
if (!active) {
|
||||
if(!active) {
|
||||
remove_feature_event(name);
|
||||
} else {
|
||||
add_event(feature_evt_name).add_property(feature_flag_name, name);
|
||||
}
|
||||
}
|
||||
Event& Batch::add_feature_variant_event(const char* const name, const char* const value) {
|
||||
return add_event(feature_evt_name)
|
||||
.add_property(feature_flag_name, name)
|
||||
.add_property(feature_flag_response_name, value);
|
||||
return add_event(feature_evt_name).add_property(feature_flag_name, name).add_property(feature_flag_response_name, value);
|
||||
}
|
||||
void Batch::remove_feature_event(const char* name) {
|
||||
for (Metrics::Event& e : _events) {
|
||||
if (strcmp(e.get_name(), feature_evt_name) == 0) {
|
||||
for(Metrics::Event& e : _events) {
|
||||
if(strcmp(e.get_name(), feature_evt_name) == 0) {
|
||||
e.remove_property(feature_flag_name, name);
|
||||
return;
|
||||
}
|
||||
@@ -49,9 +47,7 @@ void Batch::remove_feature_event(const char* name) {
|
||||
}
|
||||
cJSON* Batch::to_json() {
|
||||
cJSON* batch_json = cJSON_CreateArray();
|
||||
for (Metrics::Event& e : _events) {
|
||||
cJSON_AddItemToArray(batch_json, e.to_json(_metrics_uid.c_str()));
|
||||
}
|
||||
for(Metrics::Event& e : _events) { cJSON_AddItemToArray(batch_json, e.to_json(_metrics_uid.c_str())); }
|
||||
cJSON* message = cJSON_CreateObject();
|
||||
cJSON_AddItemToObject(message, "batch", batch_json);
|
||||
cJSON_AddStringToObject(message, "api_key", _api_key);
|
||||
@@ -66,7 +62,7 @@ char* Batch::to_json_str() {
|
||||
|
||||
void Batch::push() {
|
||||
int status_code = 0;
|
||||
if (_metrics_uid.empty() && !_warned) {
|
||||
if(_metrics_uid.empty() && !_warned) {
|
||||
ESP_LOGW(TAG, "Metrics disabled; no CID found");
|
||||
_warned = true;
|
||||
return;
|
||||
@@ -78,9 +74,7 @@ void Batch::push() {
|
||||
|
||||
status_code = metrics_http_post_request(json_str, _url);
|
||||
|
||||
if (status_code == 200 || status_code == 204) {
|
||||
_events.clear();
|
||||
}
|
||||
if(status_code == 200 || status_code == 204) { _events.clear(); }
|
||||
FREE_AND_NULL(json_str)
|
||||
ESP_LOGD(TAG, "Total duration for metrics call: %u. ", gettime_ms() - start_time);
|
||||
}
|
||||
@@ -89,32 +83,28 @@ void Batch::build_guid() {
|
||||
uint8_t raw[16];
|
||||
std::ostringstream oss;
|
||||
esp_fill_random(raw, 16);
|
||||
std::for_each(std::begin(raw), std::end(raw), [&oss](const uint8_t& byte) {
|
||||
oss << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(byte);
|
||||
});
|
||||
std::for_each(std::begin(raw), std::end(raw),
|
||||
[&oss](const uint8_t& byte) { oss << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(byte); });
|
||||
_metrics_uid = oss.str();
|
||||
}
|
||||
void Batch::assign_id() {
|
||||
size_t size = 0;
|
||||
esp_err_t esp_err = ESP_OK;
|
||||
_metrics_uid = std::string((char*)get_nvs_value_alloc_for_partition(
|
||||
NVS_DEFAULT_PART_NAME, TAG, NVS_TYPE_BLOB, "cid", &size));
|
||||
if (_metrics_uid[0] == 'G') {
|
||||
_metrics_uid = std::string((char*)get_nvs_value_alloc_for_partition(NVS_DEFAULT_PART_NAME, TAG, NVS_TYPE_BLOB, "cid", &size));
|
||||
if(_metrics_uid[0] == 'G') {
|
||||
ESP_LOGW(TAG, "Invalid ID. %s", _metrics_uid.c_str());
|
||||
_metrics_uid.clear();
|
||||
}
|
||||
if (_metrics_uid.empty()) {
|
||||
if(_metrics_uid.empty()) {
|
||||
build_guid();
|
||||
if (_metrics_uid.empty()) {
|
||||
if(_metrics_uid.empty()) {
|
||||
ESP_LOGE(TAG, "ID Failed");
|
||||
return;
|
||||
}
|
||||
ESP_LOGW(TAG, "Metrics ID: %s", _metrics_uid.c_str());
|
||||
esp_err = store_nvs_value_len_for_partition(NVS_DEFAULT_PART_NAME, TAG, NVS_TYPE_BLOB,
|
||||
"cid", _metrics_uid.c_str(), _metrics_uid.length() + 1);
|
||||
if (esp_err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Store ID failed: %s", esp_err_to_name(esp_err));
|
||||
}
|
||||
esp_err =
|
||||
store_nvs_value_len_for_partition(NVS_DEFAULT_PART_NAME, TAG, NVS_TYPE_BLOB, "cid", _metrics_uid.c_str(), _metrics_uid.length() + 1);
|
||||
if(esp_err != ESP_OK) { ESP_LOGE(TAG, "Store ID failed: %s", esp_err_to_name(esp_err)); }
|
||||
}
|
||||
}
|
||||
} // namespace Metrics
|
||||
|
||||
Reference in New Issue
Block a user