struct service_tag_s * service_tag_dup(struct service_tag_s *src) { struct service_tag_s *result; if (!src) return NULL; result = g_malloc0(sizeof(struct service_tag_s)); service_tag_copy(result, src); return result; }
struct conscience_srv_s * conscience_srvtype_refresh(struct conscience_srvtype_s *srvtype, struct service_info_s *si) { g_assert_nonnull (srvtype); g_assert_nonnull (si); struct conscience_srvid_s srvid; memcpy(&(srvid.addr), &(si->addr), sizeof(addr_info_t)); struct service_tag_s *tag_first = service_info_get_tag(si->tags, NAME_TAGNAME_RAWX_FIRST); gboolean really_first = FALSE; /*register the service if necessary */ struct conscience_srv_s *p_srv = conscience_srvtype_get_srv(srvtype, &srvid); if (!p_srv) { p_srv = conscience_srvtype_register_srv(srvtype, NULL, &srvid); g_assert_nonnull (p_srv); really_first = tag_first && tag_first->type == STVT_BOOL && tag_first->value.b; } /* refresh the tags: create missing, replace existing * (but the tags are not flushed before) */ if (si->tags) { TRACE("Refreshing tags for srv [%.*s]", (int)(LIMIT_LENGTH_SRVDESCR), p_srv->description); const guint max = si->tags->len; for (guint i = 0; i < max; i++) { struct service_tag_s *tag = g_ptr_array_index(si->tags, i); if (tag == tag_first) continue; struct service_tag_s *orig = conscience_srv_ensure_tag(p_srv, tag->name); service_tag_copy(orig, tag); } } p_srv->score.timestamp = oio_ext_monotonic_seconds (); if (si->score.value == SCORE_UNSET || si->score.value == SCORE_UNLOCK) { if (really_first) { GRID_TRACE2("SRV first [%s]", p_srv->description); p_srv->score.value = 0; p_srv->locked = TRUE; } else { if (si->score.value == SCORE_UNLOCK) { if (p_srv->locked) { GRID_TRACE2("SRV unlocked [%s]", p_srv->description); p_srv->locked = FALSE; p_srv->score.value = CLAMP (p_srv->score.value, SCORE_DOWN, SCORE_MAX); } else { GRID_TRACE2("SRV already unlocked [%s]", p_srv->description); } } else { /* UNSET, a.k.a. regular computation */ if (p_srv->locked) { GRID_TRACE2("SRV untouched [%s]", p_srv->description); } else { GError *err = NULL; if (!conscience_srv_compute_score(p_srv, &err)) { GRID_TRACE2("SRV error [%s]: (%d) %s", p_srv->description, err->code, err->message); g_clear_error (&err); } else { GRID_TRACE2("SRV refreshed [%s]", p_srv->description); } } } } } else { /* LOCK */ p_srv->score.value = CLAMP(si->score.value, SCORE_DOWN, SCORE_MAX); if (p_srv->locked) { GRID_TRACE2("SRV already locked [%s]", p_srv->description); } else { p_srv->locked = TRUE; GRID_TRACE2("SRV locked [%s]", p_srv->description); } } return p_srv; }