コード例 #1
0
ファイル: classad_c_helper.C プロジェクト: brianhlin/BLAH
  int
  classad_get_string_list_attribute (classad_context cad, 
                                     const char *attribute_name, 
                                     char ***result)
   {
    if (cad == NULL) return C_CLASSAD_INVALID_CONTEXT;

    int n_results = 0;
    (*result) = (char **)malloc(sizeof(char **));
    if ((*result) == NULL) return C_CLASSAD_OUT_OF_MEMORY;

    (*result)[0] = NULL;

    ClassAd *ad = (ClassAd *)cad;

    Value vl;
    ad->EvaluateAttr(attribute_name, vl);

    const ExprList *et_result;
    if (vl.IsListValue(et_result)) 
     {
      std::vector<ExprTree*> ads;
      et_result->GetComponents(ads);
      // Get string values.
      for(std::vector<ExprTree*>::const_iterator it = ads.begin();
          it != ads.end(); ++it) 
       {
        if ((*it)->GetKind() == ExprTree::LITERAL_NODE) 
         {
          Value v;
          EvalState       state;
          state.SetScopes( ad );

          (*it)->Evaluate(state,v);

          std::string res_str;
          if (v.IsStringValue( res_str ))
           {
            // add string value to result, which is a NULL-terminated
            // string array.
            n_results++;
            (*result) = (char **)realloc(*result, (n_results+1)*sizeof(char *));
            if ((*result) == NULL) return C_CLASSAD_OUT_OF_MEMORY;
            (*result)[n_results-1] = strdup(res_str.c_str());
            (*result)[n_results] = NULL;
           }
         }
       }
      return C_CLASSAD_NO_ERROR;
     }
    
    // The result list needs to be freed on success only.
    classad_free_string_list(*result);
    (*result) = NULL;
    return C_CLASSAD_VALUE_NOT_FOUND;
   }
コード例 #2
0
ファイル: classad_c_helper.C プロジェクト: brianhlin/BLAH
  int
  classad_get_string_attribute (classad_context cad, const char *attribute_name, 
                                char *result, int l_result)
   {
    if (cad == NULL) return C_CLASSAD_INVALID_CONTEXT;

    ClassAd *ad = (ClassAd *)cad;

    Value v;
    ad->EvaluateAttr(attribute_name, v);

    if (v.IsStringValue( result, l_result ))
     {
      return C_CLASSAD_NO_ERROR;
     }
    
    return C_CLASSAD_VALUE_NOT_FOUND;
   }
コード例 #3
0
ファイル: classad_c_helper.C プロジェクト: brianhlin/BLAH
  int
  classad_get_bool_attribute (classad_context cad, const char *attribute_name, 
                              int *result)
   {
    if (cad == NULL) return C_CLASSAD_INVALID_CONTEXT;

    ClassAd *ad = (ClassAd *)cad;

    Value v;
    ad->EvaluateAttr(attribute_name, v);

    bool tmp_res;

    if (v.IsBooleanValue( tmp_res ))
     {
      if (tmp_res) *result = 1;
      else         *result = 0;
      return C_CLASSAD_NO_ERROR;
     }
    
    return C_CLASSAD_VALUE_NOT_FOUND;
   }
コード例 #4
0
ファイル: classad_c_helper.C プロジェクト: brianhlin/BLAH
  int
  classad_get_dstring_attribute (classad_context cad, const char *attribute_name, 
                                 char **result)
   {
    if (cad == NULL) return C_CLASSAD_INVALID_CONTEXT;

    ClassAd *ad = (ClassAd *)cad;
    if (result != NULL) *result = NULL; /* For those who don't check */
                                        /* the return code... */

    Value v;
    ad->EvaluateAttr(attribute_name, v);

    std::string res_str;

    if (v.IsStringValue( res_str ))
     {
      (*result) = strdup(res_str.c_str());
      if ((*result) == NULL) return C_CLASSAD_OUT_OF_MEMORY;
      return C_CLASSAD_NO_ERROR;
     }
    
    return C_CLASSAD_VALUE_NOT_FOUND;
   }