os-cmpi-xen

changeset 132:1b777fd695b9

Updated cmpilify.[ch] from SBLIM CVS to include generic provider association interface.

Signed-off-by: Jim Fehlig <jfehlig@novell.com>
author Jim Fehlig <jfehlig@novell.com>
date Thu Jul 19 11:35:05 2007 -0600 (2007-07-19)
parents dc1be661c5ee
children 3d8f3aba0dd8
files ChangeLog src/cmpilify.c src/cmpilify.h
line diff
     1.1 --- a/ChangeLog	Wed Jul 18 16:05:48 2007 -0600
     1.2 +++ b/ChangeLog	Thu Jul 19 11:35:05 2007 -0600
     1.3 @@ -1,3 +1,9 @@
     1.4 +-------------------------------------------------------------------
     1.5 +Thu Jul 19 11:33:04 MDT 2007 - jfehlig@novell.com
     1.6 +
     1.7 +         - Updated cmpilify.[ch] from SBLIM CVS to include generic
     1.8 +           provider association interface.
     1.9 +
    1.10  -------------------------------------------------------------------
    1.11  Wed Jul 18 16:01:11 MDT 2007 - jfehlig@novell.com
    1.12  
     2.1 --- a/src/cmpilify.c	Wed Jul 18 16:05:48 2007 -0600
     2.2 +++ b/src/cmpilify.c	Thu Jul 19 11:35:05 2007 -0600
     2.3 @@ -907,3 +907,589 @@ CMPIStatus CMPILIFYInstance1RO_execQuery
     2.4     _SBLIM_RETURNSTATUS(status);
     2.5  }
     2.6  
     2.7 +
     2.8 +/****************************************************************************/
     2.9 +
    2.10 +/* Need to refine the shortcuts to match the different CMPILIFYAssociationMI */
    2.11 +#undef _BROKER
    2.12 +#define _BROKER (((CMPILIFYAssociationMI*)(mi->hdl))->brkr)
    2.13 +#undef _CLASS
    2.14 +#define _CLASS (((CMPILIFYAssociationMI*)(mi->hdl))->cn)
    2.15 +#undef _FT
    2.16 +#define _FT (((CMPILIFYAssociationMI*)(mi->hdl))->ft)
    2.17 +#define _LHSCLASS (((CMPILIFYAssociationMI*)(mi->hdl))->lhscn)
    2.18 +#define _LHSROLE (((CMPILIFYAssociationMI*)(mi->hdl))->lhsrol)
    2.19 +#define _LHSNAMESPACE (((CMPILIFYAssociationMI*)(mi->hdl))->lhsns)
    2.20 +#define _RHSCLASS (((CMPILIFYAssociationMI*)(mi->hdl))->rhscn)
    2.21 +#define _RHSROLE (((CMPILIFYAssociationMI*)(mi->hdl))->rhsrol)
    2.22 +#define _RHSNAMESPACE (((CMPILIFYAssociationMI*)(mi->hdl))->rhsns)
    2.23 +
    2.24 +static CMPIStatus gettargetinfo
    2.25 +        (CMPIAssociationMI* mi, const CMPIContext* ctx, 
    2.26 +        const CMPIObjectPath* op, const char* assocClass,
    2.27 +        const char* resultClass, const char* role, const char* resultRole,
    2.28 +        char** trgcn, char** trgns, char** query, char** lang)
    2.29 +{
    2.30 +   CMPIStatus status = {CMPI_RC_OK, NULL};
    2.31 +   char* srccn;
    2.32 +   char* srcns;
    2.33 +   CMPIObjectPath* tmpop;
    2.34 +   CMPIInstance* srcinst;
    2.35 +
    2.36 +   CMPILIFY_LOGENTER();
    2.37 +
    2.38 +   srccn = CMGetCharPtr(CMGetClassName(op, &status));
    2.39 +   srcns = CMGetCharPtr(CMGetNameSpace(op, &status));
    2.40 +
    2.41 +   /* Check assocClass filter. */
    2.42 +   if (assocClass) {
    2.43 +      tmpop = CMNewObjectPath(_BROKER, srcns, _CLASS, &status);
    2.44 +      if (!CMClassPathIsA(_BROKER, tmpop, assocClass, &status)) {
    2.45 +         CMSetStatus(&status, CMPI_RC_ERR_NOT_SUPPORTED);
    2.46 +         goto exit;
    2.47 +      }
    2.48 +   }
    2.49 +
    2.50 +   /* Get the source instance. */
    2.51 +   srcinst = CBGetInstance(_BROKER, ctx, op, NULL, &status);
    2.52 +   if ((status.rc != CMPI_RC_OK) || CMIsNullObject(srcinst)) {
    2.53 +      CMSetStatus(&status, CMPI_RC_ERR_NOT_FOUND);
    2.54 +      goto exit;
    2.55 +   }
    2.56 +
    2.57 +   /* Determine target class: LHS or RHS. */
    2.58 +   tmpop = CMNewObjectPath(_BROKER, srcns, srccn, &status);
    2.59 +   if (CMClassPathIsA(_BROKER, tmpop, _LHSCLASS, &status)) {
    2.60 +      *trgcn = _RHSCLASS;
    2.61 +      *trgns = _RHSNAMESPACE;
    2.62 +
    2.63 +      /* Check role & resultRole filter. */
    2.64 +      if ((role && (strcmp(role, _LHSROLE) != 0)) ||
    2.65 +          (resultRole && (strcmp(resultRole, _RHSROLE) != 0))) {
    2.66 +         CMSetStatus(&status, CMPI_RC_ERR_NOT_SUPPORTED);
    2.67 +         goto exit;
    2.68 +      }
    2.69 +
    2.70 +      /* Get the query for the RHS target class. */
    2.71 +      if ((_FT->getrhsquery(srcinst, query, lang) != CMPI_RC_OK) ||
    2.72 +          !*query || !*lang) {
    2.73 +         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED,
    2.74 +                              "CMPILIFY getrhsquery() failed");
    2.75 +         goto exit;
    2.76 +      }
    2.77 +
    2.78 +   } else if (CMClassPathIsA(_BROKER, tmpop, _RHSCLASS, &status)) {
    2.79 +      *trgcn = _LHSCLASS;
    2.80 +      *trgns = _LHSNAMESPACE;
    2.81 +
    2.82 +      /* Check role & resultRole filter. */
    2.83 +      if ((role && (strcmp(role, _RHSROLE) != 0)) ||
    2.84 +          (resultRole && (strcmp(resultRole, _LHSROLE) != 0))) {
    2.85 +         CMSetStatus(&status, CMPI_RC_ERR_NOT_SUPPORTED);
    2.86 +         goto exit;
    2.87 +      }
    2.88 +
    2.89 +      /* Get the query for the LHS target class. */
    2.90 +      if ((_FT->getlhsquery(srcinst, query, lang) != CMPI_RC_OK) ||
    2.91 +          !*query || !*lang) {
    2.92 +         CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_FAILED,
    2.93 +                              "CMPILIFY getlhsquery() failed");
    2.94 +         goto exit;
    2.95 +      }
    2.96 +   } else {
    2.97 +      CMSetStatus(&status, CMPI_RC_ERR_NOT_SUPPORTED);
    2.98 +      goto exit;
    2.99 +   }
   2.100 +
   2.101 + exit:
   2.102 +   CMPILIFY_LOGEXITSTATUS(status);
   2.103 +}
   2.104 +
   2.105 +/* ------------------------------------------------------------------------- */
   2.106 +
   2.107 +CMPIStatus CMPILIFYAssociation_cleanup
   2.108 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, CMPIBoolean terminating)
   2.109 +{
   2.110 +   CMPIStatus status = {CMPI_RC_OK, NULL};
   2.111 +   CMPILIFY_LOGENTER();
   2.112 +
   2.113 +   /* Run resource provider's unload(). */
   2.114 +   if (_FT->unload(terminating == CMPI_true) != CMPI_RC_OK)
   2.115 +      CMSetStatusWithChars(_BROKER, &status, (terminating == CMPI_true)?
   2.116 +                           CMPI_RC_ERR_FAILED : CMPI_RC_DO_NOT_UNLOAD,
   2.117 +                           "CMPILIFY unload() failed");
   2.118 +
   2.119 +   CMPILIFY_LOGEXITSTATUS(status);
   2.120 +}
   2.121 +
   2.122 +/* ------------------------------------------------------------------------- */
   2.123 +
   2.124 +CMPIStatus CMPILIFYAssociation_enumInstanceNames
   2.125 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
   2.126 +        const CMPIObjectPath* ref)
   2.127 +{
   2.128 +   CMPIStatus status = {CMPI_RC_OK, NULL};
   2.129 +   CMPIEnumeration* ops;
   2.130 +   CMPIObjectPath* op;
   2.131 +   CMPIData dt;
   2.132 +   CMPIObjectPath* tmpop;
   2.133 +   CMPIEnumeration* enm;
   2.134 +   CMPIData data;
   2.135 +
   2.136 +   CMPILIFY_LOGENTER();
   2.137 +
   2.138 +   /* Determine target class: LHS or RHS. */
   2.139 +   op = CMNewObjectPath(_BROKER, _LHSNAMESPACE, _LHSCLASS, &status);
   2.140 +   if ((status.rc != CMPI_RC_OK) || CMIsNullObject(op)) {
   2.141 +      CMSetStatus(&status, CMPI_RC_ERR_FAILED);
   2.142 +      goto exit;
   2.143 +   }
   2.144 +
   2.145 +   /* Get list of all LHS objectpaths. */
   2.146 +   ops = CBEnumInstanceNames(_BROKER, ctx, op, &status);
   2.147 +   if ((status.rc != CMPI_RC_OK) || CMIsNullObject(ops)) {
   2.148 +      CMSetStatus(&status, CMPI_RC_ERR_FAILED);
   2.149 +      goto exit;
   2.150 +   }
   2.151 +
   2.152 +   /* For each LHS instance, get all references. */
   2.153 +   while (CMHasNext(ops, &status)) {
   2.154 +      dt = CMGetNext(ops, &status);
   2.155 +      op = dt.value.ref;
   2.156 +fprintf(stderr,"op=%s\n",CMGetCharPtr(CDToString(_BROKER,op,NULL)));
   2.157 +
   2.158 +      enm = CBReferenceNames(_BROKER, ctx, op, _RHSCLASS, _LHSROLE, &status);
   2.159 +      if ((status.rc != CMPI_RC_OK) || CMIsNullObject(enm)) {
   2.160 +         CMSetStatus(&status, CMPI_RC_ERR_FAILED);
   2.161 +         goto exit;
   2.162 +      }
   2.163 +if (!CMHasNext(enm,NULL))
   2.164 +   fprintf(stderr,"CBReferenceNames(op, resultClass=%s, role=%s) returned nothing!\n", _RHSCLASS,_LHSROLE);
   2.165 +
   2.166 +      while (CMHasNext(enm, &status)) {
   2.167 +         data = CMGetNext(enm, &status);
   2.168 +         tmpop = data.value.ref;
   2.169 +
   2.170 +         if (CMClassPathIsA(_BROKER, tmpop, _CLASS, &status))
   2.171 +            CMReturnObjectPath(rslt, tmpop);
   2.172 +      }
   2.173 +   }
   2.174 +
   2.175 +   CMReturnDone(rslt);
   2.176 + exit:
   2.177 +   CMPILIFY_LOGEXITSTATUS(status);
   2.178 +}
   2.179 +
   2.180 +/* ------------------------------------------------------------------------- */
   2.181 +
   2.182 +CMPIStatus CMPILIFYAssociation_enumInstances
   2.183 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
   2.184 +        const CMPIObjectPath* ref, const char** properties)
   2.185 +{
   2.186 +   CMPIStatus status = {CMPI_RC_OK, NULL};
   2.187 +   CMPIEnumeration* ops;
   2.188 +   CMPIObjectPath* op;
   2.189 +   CMPIData dt;
   2.190 +   CMPIObjectPath* tmpop;
   2.191 +   CMPIInstance* tmpinst;
   2.192 +   CMPIEnumeration* enm;
   2.193 +   CMPIData data;
   2.194 +
   2.195 +   CMPILIFY_LOGENTER();
   2.196 +
   2.197 +   /* Determine target class: LHS or RHS. */
   2.198 +   op = CMNewObjectPath(_BROKER, _LHSNAMESPACE, _LHSCLASS, &status);
   2.199 +   if ((status.rc != CMPI_RC_OK) || CMIsNullObject(op)) {
   2.200 +      CMSetStatus(&status, CMPI_RC_ERR_FAILED);
   2.201 +      goto exit;
   2.202 +   }
   2.203 +
   2.204 +   /* Get list of all LHS objectpaths. */
   2.205 +   ops = CBEnumInstanceNames(_BROKER, ctx, op, &status);
   2.206 +   if ((status.rc != CMPI_RC_OK) || CMIsNullObject(ops)) {
   2.207 +      CMSetStatus(&status, CMPI_RC_ERR_FAILED);
   2.208 +      goto exit;
   2.209 +   }
   2.210 +
   2.211 +   /* For each LHS instance, get all references. */
   2.212 +   while (CMHasNext(ops, &status)) {
   2.213 +      dt = CMGetNext(ops, &status);
   2.214 +      op = dt.value.ref;
   2.215 +fprintf(stderr,"op=%s\n",CMGetCharPtr(CDToString(_BROKER,op,NULL)));
   2.216 +
   2.217 +      enm = CBReferences(_BROKER, ctx, op, _RHSCLASS, _LHSROLE, properties,
   2.218 +                         &status);
   2.219 +      if ((status.rc != CMPI_RC_OK) || CMIsNullObject(enm)) {
   2.220 +         CMSetStatus(&status, CMPI_RC_ERR_FAILED);
   2.221 +         goto exit;
   2.222 +      }
   2.223 +if (!CMHasNext(enm,NULL))
   2.224 +   fprintf(stderr,"CBReferences(op, resultClass=%s, role=%s, properties=%s) returned nothing!\n", _RHSCLASS,_LHSROLE, properties);
   2.225 +
   2.226 +      while (CMHasNext(enm, &status)) {
   2.227 +         data = CMGetNext(enm, &status);
   2.228 +         tmpinst = data.value.inst;
   2.229 +
   2.230 +         tmpop = CMGetObjectPath(tmpinst, &status);
   2.231 +         if (CMClassPathIsA(_BROKER, tmpop, _CLASS, &status))
   2.232 +            CMReturnInstance(rslt, tmpinst);
   2.233 +      }
   2.234 +   }
   2.235 +
   2.236 +   CMReturnDone(rslt);
   2.237 + exit:
   2.238 +   CMPILIFY_LOGEXITSTATUS(status);
   2.239 +}
   2.240 +
   2.241 +/* ------------------------------------------------------------------------- */
   2.242 +
   2.243 +CMPIStatus CMPILIFYAssociation_getInstance
   2.244 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
   2.245 +        const CMPIObjectPath* ref, const char** properties)
   2.246 +{
   2.247 +   CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL};
   2.248 +   CMPILIFY_LOGENTER();
   2.249 +   CMPILIFY_LOGEXITSTATUS(status);
   2.250 +}
   2.251 +
   2.252 +/* ------------------------------------------------------------------------- */
   2.253 +
   2.254 +CMPIStatus CMPILIFYAssociation_createInstance
   2.255 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
   2.256 +        const CMPIObjectPath* ref, const CMPIInstance* inst)
   2.257 +{
   2.258 +   CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL};
   2.259 +   CMPILIFY_LOGENTER();
   2.260 +   CMPILIFY_LOGEXITSTATUS(status);
   2.261 +}
   2.262 +
   2.263 +/* ------------------------------------------------------------------------- */
   2.264 +
   2.265 +CMPIStatus CMPILIFYAssociation_modifyInstance
   2.266 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
   2.267 +        const CMPIObjectPath* ref, const CMPIInstance* inst,
   2.268 +        const char** properties)
   2.269 +{
   2.270 +   CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL};
   2.271 +   CMPILIFY_LOGENTER();
   2.272 +   CMPILIFY_LOGEXITSTATUS(status);
   2.273 +}
   2.274 +
   2.275 +/* ------------------------------------------------------------------------- */
   2.276 +
   2.277 +CMPIStatus CMPILIFYAssociation_deleteInstance
   2.278 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
   2.279 +        const CMPIObjectPath* ref)
   2.280 +{
   2.281 +   CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL};
   2.282 +   CMPILIFY_LOGENTER();
   2.283 +   CMPILIFY_LOGEXITSTATUS(status);
   2.284 +}
   2.285 +
   2.286 +/* ------------------------------------------------------------------------- */
   2.287 +
   2.288 +CMPIStatus CMPILIFYAssociation_execQuery
   2.289 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
   2.290 +        const CMPIObjectPath* ref, const char* lang, const char* query)
   2.291 +{
   2.292 +   CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL};
   2.293 +   CMPILIFY_LOGENTER();
   2.294 +   CMPILIFY_LOGEXITSTATUS(status);
   2.295 +}
   2.296 +
   2.297 +/* ------------------------------------------------------------------------- */
   2.298 +
   2.299 +CMPIStatus CMPILIFYAssociation_associationCleanup
   2.300 +        (CMPIAssociationMI* mi, const CMPIContext* ctx,
   2.301 +        CMPIBoolean terminating)
   2.302 +{
   2.303 +   CMPIStatus status = {CMPI_RC_OK, NULL};
   2.304 +   CMPILIFY_LOGENTER();
   2.305 +
   2.306 +   if (_FT->unload(terminating == CMPI_true) != CMPI_RC_OK)
   2.307 +      CMSetStatusWithChars(_BROKER, &status, (terminating == CMPI_true)?
   2.308 +                           CMPI_RC_ERR_FAILED : CMPI_RC_DO_NOT_UNLOAD,
   2.309 +                           "CMPILIFY unload() failed");
   2.310 +
   2.311 +   CMPILIFY_LOGEXITSTATUS(status);
   2.312 +}
   2.313 +
   2.314 +/* ------------------------------------------------------------------------- */
   2.315 +
   2.316 +CMPIStatus CMPILIFYAssociation_associators
   2.317 +        (CMPIAssociationMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
   2.318 +        const CMPIObjectPath* op, const char* assocClass,
   2.319 +        const char* resultClass, const char* role, const char* resultRole,
   2.320 +        const char** properties)
   2.321 +{
   2.322 +   CMPIStatus status = {CMPI_RC_OK, NULL};
   2.323 +   char* trgcn;
   2.324 +   char* trgns;
   2.325 +   char* query = NULL;
   2.326 +   char* lang = NULL;
   2.327 +   CMPIObjectPath* tmpop;
   2.328 +   CMPIEnumeration* enm;
   2.329 +   CMPIData data;
   2.330 +   CMPIInstance* tmpinst;
   2.331 +
   2.332 +   CMPILIFY_LOGENTER();
   2.333 +
   2.334 +   status = gettargetinfo(mi,ctx,op,assocClass,resultClass,role,resultRole,
   2.335 +                          &trgcn, &trgns, &query, &lang);
   2.336 +   if (status.rc != CMPI_RC_OK) {
   2.337 +      /* Filter checks failed so just return OK w/o results. */
   2.338 +      if (status.rc == CMPI_RC_ERR_NOT_SUPPORTED)
   2.339 +         CMSetStatus(&status, CMPI_RC_OK);
   2.340 +      goto exit;
   2.341 +   }
   2.342 +
   2.343 +   tmpop = CMNewObjectPath(_BROKER, trgns, trgcn, &status);
   2.344 +   if ((status.rc != CMPI_RC_OK) || CMIsNullObject(tmpop)) {
   2.345 +      CMSetStatus(&status, CMPI_RC_ERR_FAILED);
   2.346 +      goto exit;
   2.347 +   }
   2.348 +
   2.349 +   enm = CBExecQuery(_BROKER, ctx, tmpop, query, lang, &status);
   2.350 +   if ((status.rc != CMPI_RC_OK) || CMIsNullObject(enm)) {
   2.351 +      CMSetStatus(&status, CMPI_RC_ERR_FAILED);
   2.352 +      goto exit;
   2.353 +   }
   2.354 + 
   2.355 +   while (CMHasNext(enm, &status)) {
   2.356 +      data = CMGetNext(enm, &status);
   2.357 +      tmpinst = data.value.inst;
   2.358 +      tmpop = CMGetObjectPath(tmpinst, &status);
   2.359 +
   2.360 +      /* Check resultClass filter. */
   2.361 +      if (!resultClass || CMClassPathIsA(_BROKER, tmpop, resultClass, &status)) 
   2.362 +         CMReturnInstance(rslt, tmpinst);
   2.363 +   }
   2.364 + 
   2.365 +   CMReturnDone(rslt);
   2.366 + exit:
   2.367 +   if (query) free(query);
   2.368 +   if (lang) free(lang);
   2.369 +   CMPILIFY_LOGEXITSTATUS(status);
   2.370 +}
   2.371 +
   2.372 +/* ------------------------------------------------------------------------- */
   2.373 +
   2.374 +CMPIStatus CMPILIFYAssociation_associatorNames
   2.375 +        (CMPIAssociationMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
   2.376 +        const CMPIObjectPath* op, const char* assocClass,
   2.377 +        const char* resultClass, const char* role, const char* resultRole)
   2.378 +{
   2.379 +   CMPIStatus status = {CMPI_RC_OK, NULL};
   2.380 +   char* trgcn;
   2.381 +   char* trgns;
   2.382 +   char* query = NULL;
   2.383 +   char* lang = NULL;
   2.384 +   CMPIObjectPath* tmpop;
   2.385 +   CMPIEnumeration* enm;
   2.386 +   CMPIData data;
   2.387 +   CMPIInstance* tmpinst;
   2.388 +
   2.389 +   CMPILIFY_LOGENTER();
   2.390 +
   2.391 +   status = gettargetinfo(mi,ctx,op,assocClass,resultClass,role,resultRole,
   2.392 +                          &trgcn, &trgns, &query, &lang);
   2.393 +   if (status.rc != CMPI_RC_OK) {
   2.394 +      /* Filter checks failed so just return OK w/o results. */
   2.395 +      if (status.rc == CMPI_RC_ERR_NOT_SUPPORTED)
   2.396 +         CMSetStatus(&status, CMPI_RC_OK);
   2.397 +      goto exit;
   2.398 +   }
   2.399 +
   2.400 +   tmpop = CMNewObjectPath(_BROKER, trgns, trgcn, &status);
   2.401 +   if ((status.rc != CMPI_RC_OK) || CMIsNullObject(tmpop)) {
   2.402 +      CMSetStatus(&status, CMPI_RC_ERR_FAILED);
   2.403 +      goto exit;
   2.404 +   }
   2.405 +
   2.406 +   enm = CBExecQuery(_BROKER, ctx, tmpop, query, lang, &status);
   2.407 +   if ((status.rc != CMPI_RC_OK) || CMIsNullObject(enm)) {
   2.408 +      CMSetStatus(&status, CMPI_RC_ERR_FAILED);
   2.409 +      goto exit;
   2.410 +   }
   2.411 +
   2.412 +   while (CMHasNext(enm, &status)) {
   2.413 +      data = CMGetNext(enm, &status);
   2.414 +      tmpinst = data.value.inst;
   2.415 +      tmpop = CMGetObjectPath(tmpinst, &status);
   2.416 +      status = CMSetNameSpace(tmpop,trgns);
   2.417 +
   2.418 +      /* Check resultClass filter. */
   2.419 +      if (!resultClass || CMClassPathIsA(_BROKER, tmpop, resultClass, &status))
   2.420 +         CMReturnObjectPath(rslt, tmpop);
   2.421 +   }
   2.422 +
   2.423 +   CMReturnDone(rslt);
   2.424 + exit:
   2.425 +   if (query) free(query);
   2.426 +   if (lang) free(lang);
   2.427 +   CMPILIFY_LOGEXITSTATUS(status);
   2.428 +}
   2.429 +
   2.430 +/* ------------------------------------------------------------------------- */
   2.431 +
   2.432 +CMPIStatus CMPILIFYAssociation_references
   2.433 +        (CMPIAssociationMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
   2.434 +        const CMPIObjectPath* op, const char* resultClass, const char* role,
   2.435 +        const char** properties)
   2.436 +{
   2.437 +   CMPIStatus status = {CMPI_RC_OK, NULL};
   2.438 +   char* trgcn;
   2.439 +   char* trgns;
   2.440 +   char* query = NULL;
   2.441 +   char* lang = NULL;
   2.442 +   CMPIObjectPath* tmpop;
   2.443 +   CMPIEnumeration* enm;
   2.444 +   CMPIData data;
   2.445 +   CMPIInstance* tmpinst;
   2.446 +   char* ns;
   2.447 +   CMPIObjectPath* assocop;
   2.448 +   CMPIInstance* associnst;
   2.449 +  
   2.450 +   CMPILIFY_LOGENTER();
   2.451 +
   2.452 +   status = gettargetinfo(mi,ctx,op,NULL,resultClass,role,NULL,
   2.453 +                          &trgcn, &trgns, &query, &lang);
   2.454 +   if (status.rc != CMPI_RC_OK) {
   2.455 +      /* Filter checks failed so just return OK w/o results. */
   2.456 +      if (status.rc == CMPI_RC_ERR_NOT_SUPPORTED)
   2.457 +         CMSetStatus(&status, CMPI_RC_OK);
   2.458 +      goto exit;
   2.459 +   }
   2.460 +
   2.461 +   tmpop = CMNewObjectPath(_BROKER, trgns, trgcn, &status);
   2.462 +   if ((status.rc != CMPI_RC_OK) || CMIsNullObject(tmpop)) {
   2.463 +      CMSetStatus(&status, CMPI_RC_ERR_FAILED);
   2.464 +      goto exit;
   2.465 +   }
   2.466 +
   2.467 +   enm = CBExecQuery(_BROKER, ctx, tmpop, query, lang, &status);
   2.468 +   if ((status.rc != CMPI_RC_OK) || CMIsNullObject(enm)) {
   2.469 +      CMSetStatus(&status, CMPI_RC_ERR_FAILED);
   2.470 +      goto exit;
   2.471 +   }
   2.472 +
   2.473 +   ns = CMGetCharPtr(CMGetNameSpace(op, &status));
   2.474 +
   2.475 +   while (CMHasNext(enm, &status)) {
   2.476 +      data = CMGetNext(enm, &status);
   2.477 +      tmpinst = data.value.inst;
   2.478 +      tmpop = CMGetObjectPath(tmpinst, &status);
   2.479 +      status = CMSetNameSpace(tmpop,trgns);
   2.480 +
   2.481 +      /* Check resultClass filter. */
   2.482 +      if (resultClass && !CMClassPathIsA(_BROKER, tmpop, resultClass, &status))
   2.483 +         continue;
   2.484 +
   2.485 +      /* Create association instance. */
   2.486 +      assocop = CMNewObjectPath(_BROKER, ns, _CLASS, &status);
   2.487 +      if ((status.rc != CMPI_RC_OK) || CMIsNullObject(assocop)) {
   2.488 +         CMSetStatus(&status, CMPI_RC_ERR_FAILED);
   2.489 +         goto exit;
   2.490 +      }
   2.491 +
   2.492 +      associnst = CMNewInstance(_BROKER, assocop, &status);
   2.493 +      if ((status.rc != CMPI_RC_OK) || CMIsNullObject(associnst)) {
   2.494 +         CMSetStatus(&status, CMPI_RC_ERR_FAILED);
   2.495 +         goto exit;
   2.496 +      }
   2.497 +
   2.498 +      /* Assign association references appropriately. */
   2.499 +      if (strcmp(trgcn, _LHSCLASS) == 0) {
   2.500 +         CMSetProperty(associnst, _LHSROLE, (CMPIValue*)&tmpop, CMPI_ref);
   2.501 +         CMSetProperty(associnst, _RHSROLE, (CMPIValue*)&op, CMPI_ref);
   2.502 +      } else {
   2.503 +         CMSetProperty(associnst, _LHSROLE, (CMPIValue*)&op, CMPI_ref);
   2.504 +         CMSetProperty(associnst, _RHSROLE, (CMPIValue*)&tmpop, CMPI_ref);
   2.505 +      }
   2.506 +      CMReturnInstance(rslt, associnst);
   2.507 +   }
   2.508 +
   2.509 +   CMReturnDone(rslt);
   2.510 + exit:
   2.511 +   if (query) free(query);
   2.512 +   if (lang) free(lang);
   2.513 +   CMPILIFY_LOGEXITSTATUS(status);
   2.514 +}
   2.515 +
   2.516 +/* ------------------------------------------------------------------------- */
   2.517 +
   2.518 +CMPIStatus CMPILIFYAssociation_referenceNames
   2.519 +        (CMPIAssociationMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
   2.520 +        const CMPIObjectPath* op, const char* resultClass, const char* role)
   2.521 +{
   2.522 +   CMPIStatus status = {CMPI_RC_OK, NULL};
   2.523 +   char* trgcn;
   2.524 +   char* trgns;
   2.525 +   char* query = NULL;
   2.526 +   char* lang = NULL;
   2.527 +   CMPIObjectPath* tmpop;
   2.528 +   CMPIEnumeration* enm;
   2.529 +   CMPIData data;
   2.530 +   CMPIInstance* tmpinst;
   2.531 +   char* ns;
   2.532 +   CMPIObjectPath* assocop;
   2.533 +
   2.534 +   CMPILIFY_LOGENTER();
   2.535 +
   2.536 +   status = gettargetinfo(mi,ctx,op,NULL,resultClass,role,NULL,
   2.537 +                          &trgcn, &trgns, &query, &lang);
   2.538 +   if (status.rc != CMPI_RC_OK) {
   2.539 +      /* Filter checks failed so just return OK w/o results. */
   2.540 +      if (status.rc == CMPI_RC_ERR_NOT_SUPPORTED)
   2.541 +         CMSetStatus(&status, CMPI_RC_OK);
   2.542 +      goto exit;
   2.543 +   }
   2.544 +
   2.545 +   tmpop = CMNewObjectPath(_BROKER, trgns, trgcn, &status);
   2.546 +   if ((status.rc != CMPI_RC_OK) || CMIsNullObject(tmpop)) {
   2.547 +      CMSetStatus(&status, CMPI_RC_ERR_FAILED);
   2.548 +      goto exit;
   2.549 +   }
   2.550 +
   2.551 +   enm = CBExecQuery(_BROKER, ctx, tmpop, query, lang, &status);
   2.552 +   if ((status.rc != CMPI_RC_OK) || CMIsNullObject(enm)) {
   2.553 +      CMSetStatus(&status, CMPI_RC_ERR_FAILED);
   2.554 +      goto exit;
   2.555 +   }
   2.556 +
   2.557 +   ns = CMGetCharPtr(CMGetNameSpace(op, &status));
   2.558 +
   2.559 +   while (CMHasNext(enm, &status)) {
   2.560 +      data = CMGetNext(enm, &status);
   2.561 +      tmpinst = data.value.inst;
   2.562 +      tmpop = CMGetObjectPath(tmpinst, &status);
   2.563 +      status = CMSetNameSpace(tmpop,trgns);
   2.564 +
   2.565 +      /* Check resultClass filter. */
   2.566 +      if (resultClass && !CMClassPathIsA(_BROKER, tmpop, resultClass, &status))
   2.567 +         continue;
   2.568 +
   2.569 +      /* Create association objectpath. */
   2.570 +      assocop = CMNewObjectPath(_BROKER, ns, _CLASS, &status);
   2.571 +      if ((status.rc != CMPI_RC_OK) || CMIsNullObject(assocop)) {
   2.572 +         CMSetStatus(&status, CMPI_RC_ERR_FAILED);
   2.573 +         goto exit;
   2.574 +      }
   2.575 +
   2.576 +      /* Assign association references appropriately. */
   2.577 +      if (strcmp(trgcn, _LHSCLASS) == 0) {
   2.578 +         CMAddKey(assocop, _LHSROLE, (CMPIValue*)&tmpop, CMPI_ref);
   2.579 +         CMAddKey(assocop, _RHSROLE, (CMPIValue*)&op, CMPI_ref);
   2.580 +      } else {
   2.581 +         CMAddKey(assocop, _LHSROLE, (CMPIValue*)&op, CMPI_ref);
   2.582 +         CMAddKey(assocop, _RHSROLE, (CMPIValue*)&tmpop, CMPI_ref);
   2.583 +      }
   2.584 +      CMReturnObjectPath(rslt, assocop);
   2.585 +   }
   2.586 +
   2.587 +   CMReturnDone(rslt);
   2.588 + exit:
   2.589 +   if (query) free(query);
   2.590 +   if (lang) free(lang);
   2.591 +   CMPILIFY_LOGEXITSTATUS(status);
   2.592 +}
     3.1 --- a/src/cmpilify.h	Wed Jul 18 16:05:48 2007 -0600
     3.2 +++ b/src/cmpilify.h	Thu Jul 19 11:35:05 2007 -0600
     3.3 @@ -15,8 +15,8 @@
     3.4   * Description:    Generic CMPILIFY instance provider.
     3.5  */
     3.6  
     3.7 -#ifndef _CMPILIFY_H_
     3.8 -#define _CMPILIFY_H_
     3.9 +#ifndef _CMPILIFY_H
    3.10 +#define _CMPILIFY_H
    3.11  
    3.12  #include <cmpidt.h>
    3.13  
    3.14 @@ -261,4 +261,177 @@ CMPIInstanceMI* pn##_Create_InstanceMI(c
    3.15  };
    3.16  
    3.17  
    3.18 -#endif /* _CMPILIFY_H_ */
    3.19 +/*****************************************************************************/
    3.20 +
    3.21 +/* ------------------------------------------------------------------------- */
    3.22 +/* Generic CMPILIFY association provider API.                                */
    3.23 +/* ------------------------------------------------------------------------- */
    3.24 +typedef struct {
    3.25 +   CMPIrc (*load)();
    3.26 +   CMPIrc (*unload)(const int terminating);
    3.27 +   CMPIrc (*getlhsquery)(const CMPIInstance* rhsinstance, char** query,
    3.28 +                         char** lang);
    3.29 +   CMPIrc (*getrhsquery)(const CMPIInstance* lhsinstance, char** query,
    3.30 +                         char** lang);
    3.31 +} CMPILIFYAssociationMIFT;
    3.32 +
    3.33 +/* ------------------------------------------------------------------------- */
    3.34 +/* Generic CMPILIFY association provider encapsulated object.                */
    3.35 +/* ------------------------------------------------------------------------- */
    3.36 +typedef struct {
    3.37 +   void* hdl;                     /* Handle to implementation-specific data. */
    3.38 +   const CMPIBroker* brkr;    /* CIMOM handle, initialized on provider load. */
    3.39 +   char* cn;                            /* Association provider's CIM class. */
    3.40 +   char* lhscn;                                 /* Left-hand-side CIM class. */
    3.41 +   char* lhsrol;                 /* Left-hand-side role/assoc property name. */
    3.42 +   char* lhsns;                    /* Namespace of left-hand-side CIM class. */
    3.43 +   char* rhscn;                                /* Right-hand-side CIM class. */
    3.44 +   char* rhsrol;                /* Right-hand-side role/assoc property name. */
    3.45 +   char* rhsns;                   /* Namespace of right-hand-side CIM class. */
    3.46 +   CMPILIFYAssociationMIFT* ft;  /* Abstract association API function table. */
    3.47 +} CMPILIFYAssociationMI;
    3.48 +
    3.49 +/* ------------------------------------------------------------------------- */
    3.50 +/* Generic CMPILIFY association/instance provider intrinsic CMPI functions.  */
    3.51 +/* ------------------------------------------------------------------------- */
    3.52 +CMPIStatus CMPILIFYAssociation_cleanup
    3.53 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, CMPIBoolean terminating);
    3.54 +
    3.55 +CMPIStatus CMPILIFYAssociation_enumInstanceNames
    3.56 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
    3.57 +        const CMPIObjectPath* ref);
    3.58 +
    3.59 +CMPIStatus CMPILIFYAssociation_enumInstances
    3.60 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
    3.61 +        const CMPIObjectPath* ref, const char** properties);
    3.62 +
    3.63 +CMPIStatus CMPILIFYAssociation_getInstance
    3.64 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
    3.65 +        const CMPIObjectPath* ref, const char** properties);
    3.66 +
    3.67 +CMPIStatus CMPILIFYAssociation_createInstance
    3.68 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
    3.69 +        const CMPIObjectPath* ref, const CMPIInstance* inst);
    3.70 +
    3.71 +CMPIStatus CMPILIFYAssociation_modifyInstance
    3.72 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
    3.73 +        const CMPIObjectPath* ref, const CMPIInstance* inst,
    3.74 +        const char** properties);
    3.75 +
    3.76 +CMPIStatus CMPILIFYAssociation_deleteInstance
    3.77 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
    3.78 +        const CMPIObjectPath* ref);
    3.79 +
    3.80 +CMPIStatus CMPILIFYAssociation_execQuery
    3.81 +        (CMPIInstanceMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
    3.82 +        const CMPIObjectPath* ref, const char* lang, const char* query);
    3.83 +
    3.84 +
    3.85 +CMPIStatus CMPILIFYAssociation_associationCleanup
    3.86 +        (CMPIAssociationMI* mi, const CMPIContext* ctx,
    3.87 +        CMPIBoolean terminating);
    3.88 +
    3.89 +CMPIStatus CMPILIFYAssociation_associators
    3.90 +        (CMPIAssociationMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
    3.91 +        const CMPIObjectPath* op, const char* assocClass,
    3.92 +        const char* resultClass, const char* role, const char* resultRole,
    3.93 +        const char** properties);
    3.94 +
    3.95 +CMPIStatus CMPILIFYAssociation_associatorNames
    3.96 +        (CMPIAssociationMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
    3.97 +        const CMPIObjectPath* op, const char* assocClass,
    3.98 +        const char* resultClass, const char* role, const char* resultRole);
    3.99 +
   3.100 +CMPIStatus CMPILIFYAssociation_references
   3.101 +        (CMPIAssociationMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
   3.102 +        const CMPIObjectPath* op, const char* resultClass, const char* role,
   3.103 +        const char** properties);
   3.104 +
   3.105 +CMPIStatus CMPILIFYAssociation_referenceNames
   3.106 +        (CMPIAssociationMI* mi, const CMPIContext* ctx, const CMPIResult* rslt,
   3.107 +        const CMPIObjectPath* op, const char* resultClass, const char* role);
   3.108 +
   3.109 +/* ------------------------------------------------------------------------- */
   3.110 +/* Macro to generate _Create_InstanceMI and _Create_AssociationMI entry      */
   3.111 +/* points, setup function tables to the shared CMPILIFY instance/association */
   3.112 +/* provider intrinsic CMPI functions, and setup function table to the        */
   3.113 +/* provider-specific association API functions.                              */
   3.114 +/* ------------------------------------------------------------------------- */
   3.115 +#define CMPILIFYAssociationMIStub(cn,pn,lhscn,lhsrol,lhsns,rhscn,rhsrol,rhsns,mi) \
   3.116 +static CMPILIFYAssociationMIFT _CMPILIFYMIFT = { \
   3.117 +   load, \
   3.118 +   unload, \
   3.119 +   getlhsquery, \
   3.120 +   getrhsquery, \
   3.121 +}; \
   3.122 +\
   3.123 +static CMPILIFYAssociationMI _CMPILIFYMI = { \
   3.124 +   NULL, \
   3.125 +   NULL, \
   3.126 +   #cn, \
   3.127 +   #lhscn, \
   3.128 +   #lhsrol, \
   3.129 +   #lhsns, \
   3.130 +   #rhscn, \
   3.131 +   #rhsrol, \
   3.132 +   #rhsns, \
   3.133 +   &_CMPILIFYMIFT, \
   3.134 +}; \
   3.135 +\
   3.136 +static CMPIInstanceMIFT _CMPIINSTMIFT = { \
   3.137 +   CMPICurrentVersion, \
   3.138 +   CMPICurrentVersion, \
   3.139 +   #pn, \
   3.140 +   CMPILIFYAssociation_cleanup, \
   3.141 +   CMPILIFYAssociation_enumInstanceNames, \
   3.142 +   CMPILIFYAssociation_enumInstances, \
   3.143 +   CMPILIFYAssociation_getInstance, \
   3.144 +   CMPILIFYAssociation_createInstance, \
   3.145 +   CMPILIFYAssociation_modifyInstance, \
   3.146 +   CMPILIFYAssociation_deleteInstance, \
   3.147 +   CMPILIFYAssociation_execQuery, \
   3.148 +}; \
   3.149 +\
   3.150 +EXTERN_C \
   3.151 +CMPIInstanceMI* pn##_Create_InstanceMI(const CMPIBroker* brkr, \
   3.152 +                                       const CMPIContext* ctx, \
   3.153 +                                       CMPIStatus* rc) { \
   3.154 +   static CMPIInstanceMI _CMPIMI = { \
   3.155 +      (void*)&_CMPILIFYMI, \
   3.156 +      &_CMPIINSTMIFT, \
   3.157 +   }; \
   3.158 +   mi = &_CMPIMI; \
   3.159 +   ((CMPILIFYAssociationMI*)(mi->hdl))->brkr = brkr; \
   3.160 +   if (((CMPILIFYAssociationMI*)(mi->hdl))->ft->load() != CMPI_RC_OK) \
   3.161 +      mi = NULL; \
   3.162 +   return (CMPIInstanceMI*)mi; \
   3.163 +}; \
   3.164 +\
   3.165 +static CMPIAssociationMIFT _CMPIASSOCMIFT = { \
   3.166 +   CMPICurrentVersion, \
   3.167 +   CMPICurrentVersion, \
   3.168 +   #pn, \
   3.169 +   CMPILIFYAssociation_associationCleanup, \
   3.170 +   CMPILIFYAssociation_associators, \
   3.171 +   CMPILIFYAssociation_associatorNames, \
   3.172 +   CMPILIFYAssociation_references, \
   3.173 +   CMPILIFYAssociation_referenceNames, \
   3.174 +}; \
   3.175 +\
   3.176 +EXTERN_C \
   3.177 +CMPIAssociationMI* pn##_Create_AssociationMI(const CMPIBroker* brkr, \
   3.178 +                                             const CMPIContext* ctx, \
   3.179 +                                             CMPIStatus* rc) { \
   3.180 +   static CMPIAssociationMI _CMPIMI = { \
   3.181 +      (void*)&_CMPILIFYMI, \
   3.182 +      &_CMPIASSOCMIFT, \
   3.183 +   }; \
   3.184 +   mi = &_CMPIMI; \
   3.185 +   ((CMPILIFYAssociationMI*)(mi->hdl))->brkr = brkr; \
   3.186 +   if (((CMPILIFYAssociationMI*)(mi->hdl))->ft->load() != CMPI_RC_OK) \
   3.187 +      mi = NULL; \
   3.188 +   return (CMPIAssociationMI*)mi; \
   3.189 +};
   3.190 +
   3.191 +
   3.192 +#endif // _CMPILIFY_H