static STATUS GM_subpindex(i4 msg, PTR cdata, i4 linstance, char *instance, PTR *instdata ) { STATUS cl_stat = MO_NO_INSTANCE; GM_PLACE_BLK *pb; SPBLK lookup; lookup.key = instance; pb = (GM_PLACE_BLK *)SPlookup( &lookup, &GM_globals.gwm_places ); switch( msg ) { case MO_GET: if( pb != NULL ) cl_stat = OK; break; case MO_GETNEXT: if( pb != NULL ) { pb = (GM_PLACE_BLK *) SPfnext( &pb->place_blk ); } else /* didn't find directly */ { if( *instance == EOS ) pb = (GM_PLACE_BLK *)SPfhead( &GM_globals.gwm_places ); else break; } if( pb == NULL ) cl_stat = MO_NO_NEXT; else cl_stat = MOstrout( MO_INSTANCE_TRUNCATED, pb->place_key, linstance, instance ); break; default: cl_stat = MO_BAD_MSG; break; } *instdata = (PTR)pb; return( cl_stat ); }
STATUS GM_cindex(i4 msg, PTR cdata, i4 linstance, char *instance, PTR *instdata ) { STATUS cl_stat = MO_NO_INSTANCE; GM_PLACE_BLK *pb; GM_CONN_BLK *cb; GM_SRVR_BLK *sb; PTR conn_key; i4 got_place = FALSE; i4 got_srvr = FALSE; GM_dc_conn_instance( instance, &conn_key ); do { if( GM_gt_sem( &GM_globals.gwm_places_sem ) != OK ) break; else got_place = TRUE; switch( msg ) { case MO_GET: cl_stat = GM_gt_conn( instance, conn_key, &pb, &cb ); if( cl_stat == OK ) { /* assert: pb->place_sem is now held */ got_srvr = TRUE; sb = &pb->place_srvr; } break; case MO_GETNEXT: /* empty instance means find first connection */ if( *instance == EOS ) { pb = NULL; cb = NULL; } else /* next after known connection */ { /* if input instance doesn't exist, NO_INSTANCE */ cl_stat = GM_gt_conn( instance, conn_key, &pb, &cb ); if( cl_stat != OK ) break; got_srvr = TRUE; sb = &pb->place_srvr; } do /* search for next connection */ { if( got_srvr ) { GM_release_sem( &pb->place_sem ); got_srvr = FALSE; } /* if we have cb, try next on this server */ if( cb != NULL ) cb = (GM_CONN_BLK *)SPfnext( &cb->conn_blk ); /* if still null, try next server */ if( cb == NULL ) { /* may be null on first call to find first. */ if( pb == NULL ) { pb = (GM_PLACE_BLK *)SPfhead( &GM_globals.gwm_places ); } else /* not initial trip */ { sb = &pb->place_srvr; pb = (GM_PLACE_BLK *)SPfnext( &pb->place_blk ); } /* if this is a server, grab sem and then the head of the connection tree. */ if( pb != NULL && pb->place_type == GM_PLACE_SRVR ) { sb = &pb->place_srvr; if( GM_gt_sem( &pb->place_sem ) != OK ) { pb = NULL; } else { got_srvr = TRUE; cb = (GM_CONN_BLK *)SPfhead( &sb->srvr_conns ); } } } } while( cb == NULL && pb != NULL ); if( cb == NULL ) { cl_stat = MO_NO_NEXT; } else { cl_stat = GM_mk_conn_instance( pb->place_blk.key, cb->conn_blk.key, linstance, instance ); } break; default: cl_stat = MO_BAD_MSG; break; } } while ( FALSE ); if( cl_stat == OK ) *instdata = (PTR)cb; if( got_place ) GM_release_sem( &GM_globals.gwm_places_sem ); if( got_srvr ) GM_release_sem( &pb->place_sem ); return( cl_stat ); }
STATUS MO_oid_set(i4 offset, i4 luserbuf, char *userbuf, i4 objsize, PTR object ) { STATUS cl_stat = OK; MO_CLASS *cp = (MO_CLASS *)object; MO_CLASS *twin_cp; MO_INSTANCE *ip; MO_INSTANCE *next_ip; MO_CLASS_DEF mo_class; do { /* if it has a twin already, error */ if( cp->twin != NULL ) { cl_stat = MO_NO_WRITE; break; } mo_class.flags = MO_CLASSID_VAR | cp->cflags; mo_class.classid = userbuf; mo_class.size = cp->size; mo_class.perms = cp->perms; mo_class.index = cp->index; mo_class.get = cp->get; mo_class.set = cp->set; mo_class.cdata = cp->cdata; mo_class.idx = cp->idx; if( OK != (cl_stat = MOclassdef( 1, &mo_class ) ) ) break; if( OK != (cl_stat = MO_getclass( userbuf, &twin_cp ) ) ) break; cp->twin = twin_cp; twin_cp->twin = cp; twin_cp->monitor = cp->monitor; /* now attach all objects of the class as twins */ for( ip = (MO_INSTANCE *)SPfhead( MO_instances ); ip != NULL ; ip = next_ip ) { next_ip = (MO_INSTANCE *)SPfnext( (SPBLK *)ip ); if( ip->classdef == cp ) { /* create one for the twin. */ cl_stat = MOattach( 0, twin_cp->node.key, ip->instance, ip->idata ); if( cl_stat != OK ) break; if( next_ip->classdef != cp ) break; } } } while( FALSE ); return( cl_stat ); }
STATUS MO_getnext(i4 valperms, i4 lclassid, i4 linstance, char *classid, char *instance, i4 *lsbufp, char *sbuf, i4 *operms ) { STATUS stat = OK; STATUS xstat = OK; MO_INSTANCE *ip; MO_CLASS *cp; /* this class */ PTR idata; MO_ngetnext++; # ifdef xDEBUG SIprintf("getnext entry: %s:%s\n", classid, instance ); # endif ip = NULL; cp = NULL; *sbuf = EOS; if( *instance != EOS ) { ip = MO_getinstance( classid, instance ); if( ip != NULL ) cp = ip->classdef; else if( OK != MO_getclass( classid, &cp ) ) stat = MO_NO_CLASSID; } else if( *classid != EOS && OK != MO_getclass( classid, &cp ) ) { stat = MO_NO_CLASSID; } /* ** Now do the real work: Given the starting point implied ** by ip and cp, find the next visible instance. */ if( stat == OK ) { if( cp == NULL ) /* start with first class */ { cp = (MO_CLASS *) SPfhead( MO_classes ); ip = NULL; } /* ** Loop over classes looking for the next valid instance. ** ** On exit, if cp != NULL, it's the class of the found instance; ** if NULL, then we never found a good instance. */ for( ; cp != NULL ; cp = (MO_CLASS *)SPnext( &cp->node, MO_classes ) ) { if( (cp->perms & MO_ANY_READ) != 0 || (valperms & MO_READ & cp->perms) != 0 ) { stat = (*cp->idx)( MO_GETNEXT, cp->cdata, linstance, instance, &idata ); if( stat == OK ) { stat = (*cp->get)( cp->offset, cp->size, idata, *lsbufp, sbuf ); if( stat == OK ) break; } } /* Now caller's ip and instance are bogus; set to search state */ ip = NULL; *instance = EOS; } if( cp == NULL ) stat = MO_NO_NEXT; if( stat == OK || MO_IS_TRUNCATED( stat ) ) xstat = MOstrout( MO_CLASSID_TRUNCATED, cp->node.key, lclassid, classid ); if( stat == OK ) stat = xstat; } *lsbufp = (i4)STlength( sbuf ); if( stat == OK || stat == MO_VALUE_TRUNCATED ) { *operms = cp->perms; (VOID) MO_tell_class( cp, instance, sbuf, MO_GET ); } # ifdef xDEBUG SIprintf("getnext exit: (%d) %s:%s - %s\n", stat, classid, instance, sbuf ); # endif return( stat ); }
STATUS MO_mon_index(i4 msg, PTR cdata, i4 linstance, char *instance, PTR *instdata ) { STATUS ret_val = OK; MO_MON_BLOCK *mp; do /* one-time through only */ { mp = NULL; if( *instance || msg == MO_GET ) { mp = MO_igetmon( instance ); if( mp == NULL ) { ret_val = MO_NO_INSTANCE; break; } else { /* FIXME */ } } else { /* FIXME */ } switch( msg ) { case MO_GET: *instdata = (PTR)mp; break; case MO_GETNEXT: mp = (MO_MON_BLOCK *)(mp ? SPfnext( &mp->node ) : SPfhead( MO_monitors ) ); if( mp == NULL ) { ret_val = MO_NO_NEXT; } else { *instdata = (PTR)mp; ret_val = MO_mon_id_get( 0, 0, (PTR)mp, linstance, instance ); if( ret_val == MO_VALUE_TRUNCATED ) ret_val = MO_INSTANCE_TRUNCATED; } break; default: ret_val = MO_BAD_MSG; break; } } while( FALSE ); return( ret_val ); }