72 #include <amxc/amxc_macros.h>
73 #include <amxc/amxc.h>
74 #include <amxp/amxp_timer.h>
104 #define QUERY_ONUS_INTERVAL_MS 10000
105 #define QUERY_ONUS_NR_TIMES 30
158 amxc_string_init(&task->
path, 0);
159 amxc_string_set(&task->
path, path);
165 amxc_string_clean(&task->
path);
179 when_null_trace(task, exit, ERROR,
"Failed to allocate memory for task_t");
183 if(amxc_llist_append(&
s_tasks, &task->
it)) {
184 SAH_TRACEZ_ERROR(
ME,
"Failed to append task to 's_tasks'");
185 SAH_TRACEZ_ERROR(
ME,
" path='%s' index=%d type=%s", path, index,
198 const char* path = amxc_string_get(&task->
path, 0);
226 const amxc_var_t*
const ret,
228 const char*
const path,
233 amxc_string_init(&buf, 0);
236 amxc_string_setf(&buf,
"%s(%s.%d)", func, path, index);
238 amxc_string_setf(&buf,
"%s(%s)", func, path);
240 const char*
const fc = amxc_string_get(&buf, 0);
243 SAH_TRACEZ_ERROR(
ME,
"%s failed: rc=%d", fc, rc);
247 const uint32_t type = amxc_var_type_of(ret);
248 if(type != AMXC_VAR_ID_HTABLE) {
249 SAH_TRACEZ_ERROR(
ME,
"%s: type of 'ret'= %d != htable", fc, type);
254 amxc_string_clean(&buf);
292 when_null(info, exit_no_cleanup);
295 if(NULL == children_char) {
300 amxc_llist_t children;
301 amxc_llist_init(&children);
304 amxc_string_init(&str, 0);
305 amxc_string_set(&str, children_char);
307 if(AMXC_STRING_SPLIT_OK != amxc_string_split_to_llist(&str, &children,
',')) {
308 SAH_TRACEZ_ERROR(
ME,
"Failed to split '%s'", children_char);
312 char child_path[256];
314 amxc_llist_iterate(it, &children) {
315 const amxc_string_t*
const child = amxc_string_from_llist_it(it);
316 const char*
const child_cstr = amxc_string_get(child, 0);
318 snprintf(child_path, 256,
"%s.%d.%s", path, index, child_cstr);
320 snprintf(child_path, 256,
"%s.%s", path, child_cstr);
323 templates ?
"indexes" :
"content", child_path);
330 amxc_llist_clean(&children, amxc_string_list_it_free);
331 amxc_string_clean(&str);
358 const char* path = amxc_string_get(&task->
path, 0);
360 SAH_TRACEZ_ERROR(
ME,
"Failed to get path");
373 if(amxc_var_add_key(cstring_t, &ret,
"path", path) == NULL) {
374 SAH_TRACEZ_ERROR(
ME,
"Failed to add 'path' to 'ret'");
378 if(amxc_var_add_key(uint32_t, &ret,
"index", task->
index) == NULL) {
379 SAH_TRACEZ_ERROR(
ME,
"Failed to add 'index' to 'ret'");
383 SAH_TRACEZ_ERROR(
ME,
"Failed to create %s.%d", path, task->
index);
388 SAH_TRACEZ_ERROR(
ME,
"Failed to update %s", path);
403 if((task->
index != 0) && (task->
index <= MAX_NR_OF_ONUS)) {
404 SAH_TRACEZ_INFO(
ME,
"XPON.ONU.%d is initialised", task->
index);
407 SAH_TRACEZ_ERROR(
ME,
"XPON.ONU: invalid index: %d: not in [1, %d]",
408 task->
index, MAX_NR_OF_ONUS);
413 amxc_var_clean(&ret);
438 const char*
const path = amxc_string_get(&task->
path, 0);
440 SAH_TRACEZ_ERROR(
ME,
"Failed to get path");
448 amxc_string_t indexes_str;
449 amxc_string_init(&indexes_str, 0);
451 amxc_llist_t indexes_list;
452 amxc_llist_init(&indexes_list);
460 const amxc_htable_t*
const htable = amxc_var_constcast(amxc_htable_t, &ret);
461 if(!amxc_htable_contains(htable,
"indexes")) {
462 SAH_TRACEZ_ERROR(
ME,
"htable 'ret' does not contain 'indexes'");
466 const char*
const indexes = GET_CHAR(&ret,
"indexes");
467 if(0 == strlen(indexes)) {
473 amxc_string_set(&indexes_str, indexes);
475 if(AMXC_STRING_SPLIT_OK != amxc_string_split_to_llist(&indexes_str, &indexes_list,
',')) {
476 SAH_TRACEZ_ERROR(
ME,
"Failed to split '%s'", indexes);
480 amxc_llist_iterate(it, &indexes_list) {
481 const amxc_string_t*
const index_str = amxc_string_from_llist_it(it);
482 const char*
const index_cstr = amxc_string_get(index_str, 0);
483 if(!amxc_string_is_numeric(index_str)) {
484 SAH_TRACEZ_ERROR(
ME,
"'%s' is not numeric", index_cstr);
487 const uint32_t index = atoi(index_cstr);
495 if(strcmp(path,
"XPON.ONU") == 0) {
496 if((0 == index) || (index > MAX_NR_OF_ONUS)) {
497 SAH_TRACEZ_ERROR(
ME,
"Invalid index: %d: not in [1, %d]", index, MAX_NR_OF_ONUS);
519 amxc_llist_clean(&indexes_list, amxc_string_list_it_free);
520 amxc_string_clean(&indexes_str);
521 amxc_var_clean(&ret);
526 if(!amxc_llist_is_empty(&
s_tasks)) {
536 static void handle_task(UNUSED amxp_timer_t* timer, UNUSED
void* priv) {
538 if(amxc_llist_is_empty(&
s_tasks)) {
539 SAH_TRACEZ_WARNING(
ME,
"No tasks");
543 amxc_llist_it_t*
const it = amxc_llist_get_first(&
s_tasks);
545 const task_t*
const task = amxc_container_of(it,
task_t, it);
555 SAH_TRACEZ_WARNING(
ME,
"Unknown task type: %d", task->
type);
582 bool all_onus_initialised =
true;
583 for(
int i = 0; i < MAX_NR_OF_ONUS; i++) {
585 all_onus_initialised =
false;
589 if(all_onus_initialised) {
590 SAH_TRACEZ_INFO(
ME,
"All %d ONUs found and initialised", MAX_NR_OF_ONUS);
591 amxp_timer_stop(timer);
598 amxp_timer_stop(timer);
625 SAH_TRACEZ_ERROR(
ME,
"Failed to create timer to handle tasks");
630 SAH_TRACEZ_ERROR(
ME,
"Failed to create timer to query ONUs");
int dm_change_object(const amxc_var_t *const args)
int dm_add_or_change_instance_impl(const amxc_var_t *const args)
bool dm_does_instance_exist(const char *path, uint32_t index)
object_id_t dm_get_object_id(const char *path)
enum _xpon_object_id object_id_t
const object_info_t * dm_get_object_info(object_id_t id)
int pon_ctrl_get_object_content(const char *const path, uint32_t index, amxc_var_t *ret)
int pon_ctrl_get_list_of_instances(const char *const path, amxc_var_t *ret)
static void schedule_remaining_tasks(void)
enum _task_type task_type_t
static void handle_task(UNUSED amxp_timer_t *timer, UNUSED void *priv)
static void task_init(task_t *const task, const char *const path, uint32_t index, task_type_t type)
static void task_clean(task_t *const task)
static bool check_return_values(int rc, const amxc_var_t *const ret, const char *func, const char *const path, uint32_t index)
static const char * task_type_to_string(task_type_t type)
static amxp_timer_t * s_timer_handle_tasks
void pplt_dm_cleanup(void)
static void query_content(const task_t *task)
static bool s_onu_initialised[MAX_NR_OF_ONUS]
static uint32_t s_cntr_query_onus
static task_t * task_create(const char *const path, uint32_t index, task_type_t type)
#define QUERY_ONUS_NR_TIMES
static void query_children(const char *const path, uint32_t index, object_id_t id, bool templates)
static amxc_llist_t s_tasks
static void query_onu_instances(amxp_timer_t *timer, UNUSED void *priv)
static void query_indexes(const task_t *task)
static amxp_timer_t * s_timer_query_onus
static void task_delete(amxc_llist_it_t *hit)
#define QUERY_ONUS_INTERVAL_MS
#define SAH_TRACEZ_DEBUG(zone, format,...)