Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,11 @@ IncludeCategories:
Priority: 2
- Regex: '^".*"$'
Priority: 4

# Add libjansson foreach macros
ForEachMacros:
- 'json_array_foreach'
- 'json_object_foreach'
- 'json_object_foreach_safe'
- 'json_object_keylen_foreach'
- 'json_object_keylen_foreach_safe'
4 changes: 2 additions & 2 deletions common/lib/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ void Log::parse(json_t *json) {
json_t *json_expression;

// cppcheck-suppress unknownMacro
json_array_foreach(json_expressions, i, json_expression)
expressions.emplace_back(json_expression);
json_array_foreach (json_expressions, i, json_expression)
expressions.emplace_back(json_expression);
}
}

Expand Down
2 changes: 1 addition & 1 deletion fpga/include/villas/fpga/card_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class CardParser {
// Parse ignored ip names to list
size_t index;
json_t *value;
json_array_foreach(ignored_ips_array, index, value) {
json_array_foreach (ignored_ips_array, index, value) {
ignored_ip_names.push_back(json_string_value(value));
}

Expand Down
2 changes: 1 addition & 1 deletion fpga/lib/card.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void CardFactory::loadSwitch(std::shared_ptr<Card> card, json_t *json_paths) {

size_t i;
json_t *json_path;
json_array_foreach(json_paths, i, json_path) {
json_array_foreach (json_paths, i, json_path) {
const char *from, *to;
int reverse = 0;

Expand Down
10 changes: 5 additions & 5 deletions fpga/lib/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ std::list<IpIdentifier> CoreFactory::parseIpIdentifier(json_t *json_ips) {

const char *ipName;
json_t *json_ip;
json_object_foreach(json_ips, ipName, json_ip) {
json_object_foreach (json_ips, ipName, json_ip) {
const char *vlnv;

json_error_t err;
Expand Down Expand Up @@ -168,7 +168,7 @@ CoreFactory::configureIps(std::list<IpIdentifier> orderedIps, json_t *json_ips,

const char *irqName;
json_t *json_irq;
json_object_foreach(json_irqs, irqName, json_irq) {
json_object_foreach (json_irqs, irqName, json_irq) {
const char *irqEntry = json_string_value(json_irq);

auto tokens = utils::tokenize(irqEntry, ":");
Expand Down Expand Up @@ -223,7 +223,7 @@ CoreFactory::configureIps(std::list<IpIdentifier> orderedIps, json_t *json_ips,
// Now find all slave address spaces this master can access
const char *bus_name;
json_t *json_bus;
json_object_foreach(json_memory_view, bus_name, json_bus) {
json_object_foreach (json_memory_view, bus_name, json_bus) {

// This IP has a memory view => it is a bus master somewhere

Expand All @@ -239,11 +239,11 @@ CoreFactory::configureIps(std::list<IpIdentifier> orderedIps, json_t *json_ips,

const char *instance_name;
json_t *json_instance;
json_object_foreach(json_bus, instance_name, json_instance) {
json_object_foreach (json_bus, instance_name, json_instance) {

const char *block_name;
json_t *json_block;
json_object_foreach(json_instance, block_name, json_block) {
json_object_foreach (json_instance, block_name, json_block) {

json_int_t base, high, size;
json_error_t err;
Expand Down
2 changes: 1 addition & 1 deletion fpga/lib/ips/pcie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void AxiPciExpressBridgeFactory::parse(Core &ip, json_t *cfg) {

json_t *json_bar;
const char *bar_name;
json_object_foreach(json_bars, bar_name, json_bar) {
json_object_foreach (json_bars, bar_name, json_bar) {
unsigned int translation;

json_error_t err;
Expand Down
2 changes: 1 addition & 1 deletion fpga/lib/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void NodeFactory::parse(Core &ip, json_t *cfg) {
if (json_ports && json_is_array(json_ports)) {
size_t index;
json_t *json_port;
json_array_foreach(json_ports, index, json_port) {
json_array_foreach (json_ports, index, json_port) {
if (not json_is_object(json_port))
throw ConfigError(json_port, "", "Port {} is not an object", index);

Expand Down
2 changes: 1 addition & 1 deletion fpga/lib/pcie_card.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ PCIeCardFactory::make(json_t *json_card, std::string card_name,
// Parse ignored ip names to list
size_t index;
json_t *value;
json_array_foreach(ignored_ips_array, index, value) {
json_array_foreach (ignored_ips_array, index, value) {
card->ignored_ip_names.push_back(json_string_value(value));
}

Expand Down
2 changes: 1 addition & 1 deletion fpga/lib/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ int fpga::createCards(json_t *config,
const char *card_name;
json_t *json_card;
std::shared_ptr<fpga::Card> card;
json_object_foreach(fpgas, card_name, json_card) {
json_object_foreach (fpgas, card_name, json_card) {
card = createCard(json_card, searchPath, vfioContainer, card_name);
if (card != nullptr) {
cards.push_back(card);
Expand Down
4 changes: 2 additions & 2 deletions lib/api/universal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void ChannelList::parse(json_t *json, bool readable, bool writable) {

size_t i;
json_t *json_channel;
json_array_foreach(json, i, json_channel) {
json_array_foreach (json, i, json_channel) {
auto channel = std::make_shared<Channel>();

channel->parse(json_channel);
Expand Down Expand Up @@ -73,7 +73,7 @@ void Channel::parse(json_t *json) {

range_options.clear();

json_array_foreach(json_range, i, json_option) {
json_array_foreach (json_range, i, json_option) {
if (!json_is_string(json_option))
throw ConfigError(json, err, "node-config-node-api-signals-range",
"Channel range options must be strings");
Expand Down
4 changes: 2 additions & 2 deletions lib/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ json_t *Config::walkStrings(json_t *root, str_walk_fcn_t cb) {
case JSON_OBJECT:
new_root = json_object();

json_object_foreach(root, key, val) {
json_object_foreach (root, key, val) {
new_val = walkStrings(val, cb);

json_object_set_new(new_root, key, new_val);
Expand All @@ -298,7 +298,7 @@ json_t *Config::walkStrings(json_t *root, str_walk_fcn_t cb) {
case JSON_ARRAY:
new_root = json_array();

json_array_foreach(root, index, val) {
json_array_foreach (root, index, val) {
new_val = walkStrings(val, cb);

json_array_append_new(new_root, new_val);
Expand Down
6 changes: 3 additions & 3 deletions lib/config_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ int villas::node::json_to_config(json_t *json, config_setting_t *parent) {
const char *key;
json_t *json_value;

json_object_foreach(json, key, json_value) {
json_object_foreach (json, key, json_value) {
type = json_to_config_type(json_typeof(json_value));

cfg = config_setting_add(parent, key, type);
Expand All @@ -113,7 +113,7 @@ int villas::node::json_to_config(json_t *json, config_setting_t *parent) {
size_t i;
json_t *json_value;

json_array_foreach(json, i, json_value) {
json_array_foreach (json, i, json_value) {
type = json_to_config_type(json_typeof(json_value));

cfg = config_setting_add(parent, nullptr, type);
Expand Down Expand Up @@ -305,7 +305,7 @@ int villas::node::json_object_extend(json_t *obj, json_t *merge) {
if (!json_is_object(obj) || !json_is_object(merge))
return -1;

json_object_foreach(merge, key, merge_value) {
json_object_foreach (merge, key, merge_value) {
obj_value = json_object_get(obj, key);
if (obj_value && json_is_object(obj_value))
ret = json_object_extend(obj_value, merge_value);
Expand Down
6 changes: 3 additions & 3 deletions lib/formats/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ int JsonFormat::unpackFlags(json_t *json_flags, struct Sample *smp) {

size_t i;
json_t *json_flag;
json_array_foreach(json_flags, i, json_flag) {
json_array_foreach (json_flags, i, json_flag) {
char *flag;
json_error_t err;
if (auto ret = json_unpack_ex(json_flag, &err, 0, "s", &flag))
Expand Down Expand Up @@ -239,7 +239,7 @@ int JsonFormat::unpackSample(json_t *json_smp, struct Sample *smp) {
smp->flags |= (int)SampleFlags::HAS_SEQUENCE;
}

json_array_foreach(json_data, i, json_value) {
json_array_foreach (json_data, i, json_value) {
if (i >= smp->capacity)
break;

Expand Down Expand Up @@ -276,7 +276,7 @@ int JsonFormat::unpackSamples(json_t *json_smps, struct Sample *const smps[],
if (!json_is_array(json_smps))
return -1;

json_array_foreach(json_smps, i, json_smp) {
json_array_foreach (json_smps, i, json_smp) {
if (i >= cnt)
break;

Expand Down
2 changes: 1 addition & 1 deletion lib/formats/json_edgeflex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ int JsonEdgeflexFormat::unpackSample(json_t *json_smp, struct Sample *smp) {
if (json_typeof(json_smp) != JSON_OBJECT)
return -1;

json_object_foreach(json_smp, key, json_value) {
json_object_foreach (json_smp, key, json_value) {
if (!strcmp(key, "created"))
json_created = json_incref(json_value);
else {
Expand Down
2 changes: 1 addition & 1 deletion lib/formats/json_reserve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ int JsonReserveFormat::unpackSample(json_t *json_smp, struct Sample *smp) {
smp->flags = 0;
smp->length = 0;

json_array_foreach(json_data, i, json_value) {
json_array_foreach (json_data, i, json_value) {
const char *name, *unit = nullptr;
double value;

Expand Down
2 changes: 1 addition & 1 deletion lib/hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void MultiSignalHook::parse(json_t *json) {
throw ConfigError(json_signals, "node-config-hook-signals",
"Setting 'signals' must be a list of signal names");

json_array_foreach(json_signals, i, json_signal) {
json_array_foreach (json_signals, i, json_signal) {
if (!json_is_string(json_signal))
throw ConfigError(json_signal, "node-config-hook-signals",
"Invalid value for setting 'signals'");
Expand Down
2 changes: 1 addition & 1 deletion lib/hook_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void HookList::parse(json_t *json, int mask, Path *o, Node *n) {

size_t i;
json_t *json_hook;
json_array_foreach(json, i, json_hook) {
json_array_foreach (json, i, json_hook) {
int ret;
const char *type;
Hook::Ptr h;
Expand Down
2 changes: 1 addition & 1 deletion lib/hooks/dp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class DPHook : public Hook {
if (!fharmonics || !coeffs)
throw MemoryAllocationError();

json_array_foreach(json_harmonics, i, json_harmonic) {
json_array_foreach (json_harmonics, i, json_harmonic) {
if (!json_is_integer(json_harmonic))
throw ConfigError(json_harmonic, "node-config-hook-dp-harmonics",
"Setting 'harmonics' must be a list of integers");
Expand Down
2 changes: 1 addition & 1 deletion lib/hooks/ebm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class EBMHook : public Hook {
if (!json_is_array(json_phases))
throw ConfigError(json_phases, "node-config-hook-ebm-phases");

json_array_foreach(json_phases, i, json_phase) {
json_array_foreach (json_phases, i, json_phase) {
int voltage, current;

ret = json_unpack_ex(json_phase, &err, 0, "[ i, i ]", &voltage, &current);
Expand Down
8 changes: 4 additions & 4 deletions lib/hooks/lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,15 @@ static void lua_pushjson(lua_State *L, json_t *json) {
switch (json_typeof(json)) {
case JSON_OBJECT:
lua_newtable(L);
json_object_foreach(json, key, json_value) {
json_object_foreach (json, key, json_value) {
lua_pushjson(L, json_value);
lua_setfield(L, -2, key);
}
break;

case JSON_ARRAY:
lua_newtable(L);
json_array_foreach(json, i, json_value) {
json_array_foreach (json, i, json_value) {
lua_pushjson(L, json_value);
lua_rawseti(L, -2, i);
}
Expand Down Expand Up @@ -359,8 +359,8 @@ void LuaHook::parseExpressions(json_t *json_sigs) {
"Setting 'signals' must be a list of dicts");

// cppcheck-suppress unknownMacro
json_array_foreach(json_sigs, i, json_sig)
expressions.emplace_back(L, json_sig);
json_array_foreach (json_sigs, i, json_sig)
expressions.emplace_back(L, json_sig);

hasExpressions = true;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/hooks/power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class PowerHook : public MultiSignalHook {

size_t i = 0;
json_t *json_pairings_value;
json_array_foreach(json_pairings, i, json_pairings_value) {
json_array_foreach (json_pairings, i, json_pairings_value) {
const char *voltageNameC = nullptr;
const char *currentNameC = nullptr;

Expand Down
2 changes: 1 addition & 1 deletion lib/kernel/tc_netem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ static int set_delay_distribution(struct rtnl_qdisc *qdisc, json_t *json) {
if (!data)
throw MemoryAllocationError();

json_array_foreach(json, idx, elm) {
json_array_foreach (json, idx, elm) {
if (!json_is_integer(elm))
return -1;

Expand Down
2 changes: 1 addition & 1 deletion lib/mapping_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ int MappingList::parse(json_t *json) {
else
return -1;

json_array_foreach(json_mapping, i, json_entry) {
json_array_foreach (json_mapping, i, json_entry) {
auto me = std::make_shared<MappingEntry>();
if (!me)
throw MemoryAllocationError();
Expand Down
2 changes: 1 addition & 1 deletion lib/node_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ int NodeList::parse(json_t *json, NodeList &all) {
break;

case JSON_ARRAY:
json_array_foreach(json, index, elm) {
json_array_foreach (json, index, elm) {
if (!json_is_string(elm))
goto invalid;

Expand Down
4 changes: 2 additions & 2 deletions lib/nodes/can.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ int villas::node::can_parse(NodeCompat *n, json_t *json) {
if (!c->out)
throw MemoryAllocationError();

json_array_foreach(json_in_signals, i, json_signal) {
json_array_foreach (json_in_signals, i, json_signal) {
ret = can_parse_signal(json_signal, n->in.signals, c->in, i);
if (ret)
throw RuntimeError("at signal {}.", i);
}

json_array_foreach(json_out_signals, i, json_signal) {
json_array_foreach (json_out_signals, i, json_signal) {
ret = can_parse_signal(json_signal, n->out.signals, c->out, i);
if (ret)
throw RuntimeError("at signal {}.", i);
Expand Down
2 changes: 1 addition & 1 deletion lib/nodes/comedi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static int comedi_parse_direction(struct comedi *c, struct comedi_direction *d,
if (!d->chanspecs)
throw MemoryAllocationError();

json_array_foreach(json_chans, i, json_chan) {
json_array_foreach (json_chans, i, json_chan) {
int num, range, aref;
ret = json_unpack_ex(json_chan, &err, 0, "{ s: i, s: i, s: i }", "channel",
&num, "range", &range, "aref", &aref);
Expand Down
4 changes: 2 additions & 2 deletions lib/nodes/exec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ int ExecNode::parse(json_t *json) {

size_t i;
json_t *json_arg;
json_array_foreach(json_exec, i, json_arg) {
json_array_foreach (json_exec, i, json_arg) {
if (!json_is_string(json_arg))
throw ConfigError(json_arg, "node-config-node-exec-exec",
"All arguments must be of string type");
Expand All @@ -90,7 +90,7 @@ int ExecNode::parse(json_t *json) {
const char *key;
json_t *json_value;

json_object_foreach(json_env, key, json_value) {
json_object_foreach (json_env, key, json_value) {
if (!json_is_string(json_value))
throw ConfigError(json_value, "node-config-node-exec-environment",
"Environment variables must be of string type");
Expand Down
2 changes: 1 addition & 1 deletion lib/nodes/iec60870.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ int SlaveNode::parse(json_t *json) {
size_t i;
std::optional<ASDUData> last_data = std::nullopt;

json_array_foreach(json_signals, i, json_signal) {
json_array_foreach (json_signals, i, json_signal) {
auto signal = signals ? signals->getByIndex(i) : Signal::Ptr{};
auto asdu_data =
ASDUData::parse(json_signal, last_data, duplicate_ioa_is_sequence);
Expand Down
2 changes: 1 addition & 1 deletion lib/nodes/iec61850.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ int villas::node::iec61850_parse_signals(json_t *json_signals,
if (json_is_array(json_signals)) {
json_t *json_signal;
size_t i;
json_array_foreach(json_signals, i, json_signal) {
json_array_foreach (json_signals, i, json_signal) {
json_unpack_ex(json_signal, &err, 0, "{ s?: s }", "iec_type", &iec_type);

// Try to deduct the IEC 61850 data type from VILLAS signal format
Expand Down
Loading