Skip to content

Commit

Permalink
RDKBWIFI-13 Using std::vector for channels in em_op_class_info_t
Browse files Browse the repository at this point in the history
  • Loading branch information
marcin-matula-2329518 committed Dec 12, 2024
1 parent 384f95c commit 8185f76
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 19 deletions.
4 changes: 4 additions & 0 deletions inc/db_easy_mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
#include "db_client.h"
#include <cjson/cJSON.h>

#include <string>
#include <vector>

class db_easy_mesh_t {

public:
Expand All @@ -44,6 +47,7 @@ class db_easy_mesh_t {

char *get_column_format(db_fmt_t fmt, unsigned int pos);
int get_strings_by_token(char *parent, int token, unsigned int argc, char *argv[]);
std::vector<std::string> get_strings_by_token(char *parent, int token);

int create_table(db_client_t& db_client);
int load_table(db_client_t& db_client);
Expand Down
4 changes: 3 additions & 1 deletion inc/em_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <uuid/uuid.h>
#include "ec_base.h"

#include <vector>

#define EM_MAX_NETWORKS 5
#define EM_MAX_NET_SSIDS 4
#define EM_MAX_DEVICES 16
Expand Down Expand Up @@ -1944,7 +1946,7 @@ typedef struct {
int tx_power;
int max_tx_power;
unsigned int num_channels;
unsigned int channels[EM_MAX_CHANNELS_IN_LIST];
std::vector<unsigned int> channels;
unsigned short mins_since_cac_comp;
unsigned short sec_remain_non_occ_dur;
unsigned int countdown_cac_comp;
Expand Down
31 changes: 31 additions & 0 deletions src/db/db_easy_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,37 @@ int db_easy_mesh_t::get_strings_by_token(char *parent, int token, unsigned int a
return num;
}

std::vector<std::string> db_easy_mesh_t::get_strings_by_token(char *parent, int token)
{
unsigned int num = 0, i;
em_long_string_t str_copy;
char *tmp, *orig;

std::vector<std::string> output;

if (*parent == 0) {
return {};
}

snprintf(str_copy, sizeof(str_copy), "%s", parent);
tmp = str_copy;
orig = str_copy;

while (tmp != NULL) {
if ((tmp = strchr(orig, token)) != NULL) {
*tmp = 0;
output.push_back(orig);
tmp++; num++;
orig = tmp;
}
}

output.push_back(orig);
num++;

return output;
}

int db_easy_mesh_t::insert_row(db_client_t& db_client, ...)
{
unsigned int i;
Expand Down
15 changes: 11 additions & 4 deletions src/dm/dm_op_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ bool dm_op_class_t::operator == (const dm_op_class_t& obj)
} else if (this->m_op_class_info.id.type == em_op_class_type_capability) {
ret += !(this->m_op_class_info.max_tx_power == obj.m_op_class_info.max_tx_power);
ret += !(this->m_op_class_info.num_channels == obj.m_op_class_info.num_channels);
ret += (memcmp(this->m_op_class_info.channels, obj.m_op_class_info.channels, sizeof(unsigned int) * EM_MAX_CHANNELS_IN_LIST) != 0);
bool isVecEqual = (this->m_op_class_info.channels == obj.m_op_class_info.channels);
if (!isVecEqual) {
ret += 1;
}
} else if (this->m_op_class_info.id.type == em_op_class_type_cac_available) {
ret += !(this->m_op_class_info.mins_since_cac_comp == obj.m_op_class_info.mins_since_cac_comp);
} else if (this->m_op_class_info.id.type == em_op_class_type_cac_non_occ) {
Expand All @@ -157,7 +160,10 @@ bool dm_op_class_t::operator == (const dm_op_class_t& obj)
(this->m_op_class_info.id.type == em_op_class_type_anticipated) ||
(this->m_op_class_info.id.type == em_op_class_type_scan_param)) {
ret += !(this->m_op_class_info.num_channels == obj.m_op_class_info.num_channels);
ret += (memcmp(this->m_op_class_info.channels, obj.m_op_class_info.channels, sizeof(unsigned int) * EM_MAX_CHANNELS_IN_LIST) != 0);
bool isVecEqual = (this->m_op_class_info.channels == obj.m_op_class_info.channels);
if (!isVecEqual) {
ret += 1;
}
}

if (ret > 0)
Expand All @@ -176,12 +182,13 @@ void dm_op_class_t::operator = (const dm_op_class_t& obj)
this->m_op_class_info.tx_power = obj.m_op_class_info.tx_power;
this->m_op_class_info.max_tx_power = obj.m_op_class_info.max_tx_power;
this->m_op_class_info.num_channels = obj.m_op_class_info.num_channels;
memcpy(this->m_op_class_info.channels, obj.m_op_class_info.channels, sizeof(unsigned int) * EM_MAX_CHANNELS_IN_LIST);
this->m_op_class_info.channels = obj.m_op_class_info.channels;
this->m_op_class_info.mins_since_cac_comp = obj.m_op_class_info.mins_since_cac_comp;
this->m_op_class_info.sec_remain_non_occ_dur = obj.m_op_class_info.sec_remain_non_occ_dur;
this->m_op_class_info.countdown_cac_comp = obj.m_op_class_info.countdown_cac_comp;
this->m_op_class_info.num_channels = obj.m_op_class_info.num_channels;
memcpy(this->m_op_class_info.channels, obj.m_op_class_info.channels, sizeof(unsigned int) * EM_MAX_CHANNELS_IN_LIST);

this->m_op_class_info.channels = obj.m_op_class_info.channels; // std::vector c++ copying
}

int dm_op_class_t::parse_op_class_id_from_key(const char *key, em_op_class_id_t *id)
Expand Down
24 changes: 11 additions & 13 deletions src/dm/dm_op_class_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
#include "dm_easy_mesh.h"
#include "dm_easy_mesh_ctrl.h"

#include <vector>

int dm_op_class_list_t::get_config(cJSON *obj_arr, void *parent, bool summary)
{
dm_op_class_t *pop_class;
Expand Down Expand Up @@ -288,8 +290,7 @@ int dm_op_class_list_t::sync_db(db_client_t& db_client, void *ctx)
em_op_class_info_t info;
em_long_string_t str, id;
mac_addr_str_t mac_str;
em_short_string_t ch_str[EM_MAX_CHANNELS_IN_LIST];
char *token_parts[EM_MAX_CHANNELS_IN_LIST], *tmp;
char *tmp;
unsigned int i = 0;
int rc = 0;

Expand All @@ -300,18 +301,15 @@ int dm_op_class_list_t::sync_db(db_client_t& db_client, void *ctx)
dm_op_class_t::parse_op_class_id_from_key(id, &info.id);
info.op_class = db_client.get_number(ctx, 2);
info.channel = db_client.get_number(ctx, 3);

db_client.get_string(ctx, str, 4);
for (i = 0; i < EM_MAX_CHANNELS_IN_LIST; i++) {
token_parts[i] = ch_str[i];
}

if ((str != NULL) && (*str != 0)) {
info.num_channels = get_strings_by_token(str, ',', EM_MAX_CHANNELS_IN_LIST, token_parts);
for (i = 0; i < info.num_channels; i++) {
info.channels[i] = atoi(token_parts[i]);
}
}
db_client.get_string(ctx, str, 4);
if ((str != NULL) && (*str != 0)) {
const auto& channels = get_strings_by_token(str, ',');
info.num_channels = channels.size();
for (i = 0; i < info.num_channels; i++) {
info.channels[i] = atoi(channels[i].c_str());
}
}

info.tx_power = db_client.get_number(ctx, 5);
info.max_tx_power = db_client.get_number(ctx, 6);
Expand Down
2 changes: 1 addition & 1 deletion src/em/em.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ int em_t::start_al_interface()
slen = sizeof(struct sockaddr_ll);

if ((sock_fd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL))) < 0) {
printf("%s:%d: Error opening socket, err:%d\n", __func__, __LINE__, errno);
printf("%s:%d: Error opening socket, err:%d name: %s\n", __func__, __LINE__, errno, m_ruid.name);
return -1;
}

Expand Down

0 comments on commit 8185f76

Please sign in to comment.