Exemple #1
0
STATIC_FUNC
void check_local_topology_cache(void *nothing)
{
	assertion(-500000, (my_topology_period < MAX_TOPOLOGY_PERIOD));

        struct avl_node *local_it;
        struct local_node *local;
	uint32_t m = 0;

	for (local_it = NULL; (local = avl_iterate_item(&local_tree, &local_it));) {

		if (local->neigh && local->neigh->dhn->on && local->best_tp_lndev) {

			struct local_topology_node *ltn = avl_find_item(&local_topology_tree, &local->neigh->dhn->on->global_id.pkid);
			struct local_topology_node tmp;

			if (!ltn) {
				my_description_changed = YES;
				return;
			}

			set_local_topology_node(&tmp, local);

			if ( (bmx_time - self->updated_timestamp) > ((uint32_t)my_topology_period * 10) && (
				check_value_deviation(ltn->txBw, tmp.txBw, 0) ||
				check_value_deviation(ltn->rxBw, tmp.rxBw, 0) ||
				check_value_deviation(ltn->txRate, tmp.txRate, 0) ||
				check_value_deviation(ltn->rxRate, tmp.rxRate, 0) )
				) {

				my_description_changed = YES;
				return;

			} else if (
				check_value_deviation(ltn->txBw, tmp.txBw, my_topology_hysteresis) ||
				check_value_deviation(ltn->rxBw, tmp.rxBw, my_topology_hysteresis) ||
				check_value_deviation(ltn->txRate, tmp.txRate, my_topology_hysteresis) ||
				check_value_deviation(ltn->rxRate, tmp.rxRate, my_topology_hysteresis)
				) {
				my_description_changed = YES;
				return;
			}

			m++;
		}
        }

	if (local_topology_tree.items != m) {
		my_description_changed = YES;
		return;
	}

	task_register(my_topology_period/10, check_local_topology_cache, NULL, -300000);
}
Exemple #2
0
STATIC_FUNC
void check_for_changed_sms(void *unused)
{
        uint16_t found_sms = 0;
        uint16_t matching_sms = 0;

        struct opt_type *opt = get_option( 0, 0, ARG_SMS );
        struct opt_parent *p = NULL;
        struct json_sms * sms = NULL;
        struct avl_node *an = NULL;

        char name[MAX_JSON_SMS_NAME_LEN];
        char data[MAX_JSON_SMS_DATA_LEN + 1];

        dbgf_all(DBGT_INFO, "checking...");

        if (extensions_fd == -1) {
                task_remove(check_for_changed_sms, NULL);
                task_register(SMS_POLLING_INTERVAL, check_for_changed_sms, NULL, 300000);
        }


        while ((sms = avl_iterate_item(&json_sms_tree, &an))) {
                sms->stale = 1;
        }

        while ((p = list_iterate(&opt->d.parents_instance_list, p))) {

                int len = 0;

                memset(name, 0, sizeof (name));
                strcpy(name, p->val);

                int fd = -1;
                char path_name[MAX_PATH_SIZE + 20] = "";
                sprintf(path_name, "%s/%s", smsTx_dir, p->val);



                if ((fd = open(path_name, O_RDONLY, 0)) < 0) {

                        dbgf_all(DBGT_INFO, "could not open %s - %s", path_name, strerror(errno));
                        continue;

                } else if ((len = read(fd, data, sizeof (data))) < 0 || len > MAX_JSON_SMS_DATA_LEN) {

                        dbgf_sys(DBGT_ERR, "sms=%s data_len>=%d MUST BE <=%d bytes! errno: %s",
                                path_name, len, MAX_JSON_SMS_DATA_LEN, strerror(errno));
                        close(fd);
                        continue;

                } else if ((sms = avl_find_item(&json_sms_tree, name)) && sms->text_len == len && !memcmp(sms->text, data, len)) {

                        matching_sms++;
                        sms->stale = 0;
                        close(fd);

                } else {

                        if (sms) {
                                avl_remove(&json_sms_tree, sms->name, -300378);
                                debugFree(sms, -300369);
                        }

                        sms = debugMalloc(sizeof (struct json_sms) +len, -300370);
                        memset(sms, 0, sizeof (struct json_sms) +len);
                        strcpy(sms->name, name);
                        sms->text_len = len;
                        sms->stale = 0;
                        memcpy(sms->text, data, len);
                        avl_insert(&json_sms_tree, sms, -300371);
                        close(fd);

                        dbgf_track(DBGT_INFO, "new sms=%s size=%d! updating description..-", path_name, sms->text_len);
                }

                found_sms++;
        }


        if (found_sms != matching_sms || found_sms != json_sms_tree.items) {

                dbgf_all(DBGT_INFO, "sms found=%d matching=%d items=%d", found_sms, matching_sms, json_sms_tree.items);

                memset(name, 0, sizeof (name));
                while ((sms = avl_next_item(&json_sms_tree, name))) {
                        memcpy(name, sms->name, sizeof (sms->name));
                        if (sms->stale) {
                                dbgf_track(DBGT_INFO, "removed sms=%s/%s size=%d! updating description...",
                                        smsTx_dir, sms->name, sms->text_len);

                                avl_remove(&json_sms_tree, sms->name, -300373);
                                debugFree(sms, -300374);
                        }
                }

                my_description_changed = YES;
        }
}