herr_t
ss_pers_state(ss_pers_t *pers, /* The persistent object link whose state is to be changed. */
ss_pers_link_state_t state /* Desired state for the link, one of the SS_PERS_LINK constants. */
)
{
SS_ENTER(ss_pers_state, herr_t);
SS_ASSERT_CLASS(pers, ss_pers_t);
switch (state) {
case SS_PERS_LINK_NULL:
ss_pers_link_setobjptr(pers, NULL);
ss_pers_link_setobjidx(pers, 0);
ss_pers_link_setscopeidx(pers, 0);
ss_pers_link_setgfileidx(pers, 0);
ss_pers_link_setopenserial(pers, 0);
break;
case SS_PERS_LINK_RESERVED:
/* What does this really mean? */
break;
case SS_PERS_LINK_CLOSED:
if (SS_PERS_LINK_NULL==ss_pers_link_state(pers)) SS_ERROR_FMT(NOTFOUND, ("link is null"));
if (SS_PERS_LINK_RESERVED==ss_pers_link_state(pers)) SS_ERROR_FMT(CORRUPT, ("mangled link"));
/* We might be able to be more efficient here, especially if the link is in a closed state already. The problem here
* is that if the link is in a closed state but the file is open then it will be updated to the memory state and the
* object will be read from the file. */
if (ss_pers_update(pers)<0) SS_ERROR(FAILED);
ss_pers_link_setobjptr(pers, NULL);
break;
case SS_PERS_LINK_MEMORY:
/* If the link is already in a memory state we probably still want to make sure the `objidx' is updated to be a direct
* index if one exists. */
if (ss_pers_update(pers)<0) SS_ERROR(FAILED);
break;
}
ss_pers_link_setstate(pers, state);
SS_CLEANUP:
SS_LEAVE(0);
}