00001 /*************************************************************** 00002 * 00003 * Copyright (C) 1990-2007, Condor Team, Computer Sciences Department, 00004 * University of Wisconsin-Madison, WI. 00005 * 00006 * Licensed under the Apache License, Version 2.0 (the "License"); you 00007 * may not use this file except in compliance with the License. You may 00008 * obtain a copy of the License at 00009 * 00010 * http://www.apache.org/licenses/LICENSE-2.0 00011 * 00012 * Unless required by applicable law or agreed to in writing, software 00013 * distributed under the License is distributed on an "AS IS" BASIS, 00014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 * See the License for the specific language governing permissions and 00016 * limitations under the License. 00017 * 00018 ***************************************************************/ 00019 00020 00021 #ifndef __CLASSAD_CCLASSAD_H_ 00022 #define __CLASSAD_CCLASSAD_H_ 00023 00024 /* 00025 This is a C interface to the classad library. 00026 This allows programs to use the ClassAd library in 00027 a compiler-independent fashion with traditional constructs 00028 such as integers and C strings. No special compiler flags 00029 or other packages are necessary to use this interface. 00030 */ 00031 00032 #ifdef __cplusplus 00033 BEGIN_NAMESPACE( classad ) 00034 extern "C" { 00035 #endif 00036 00037 struct classad; 00038 00039 /* 00040 Create and delete ClassAds. 00041 If str is null, the ad is empty. 00042 If str is non-null, the ad is parsed from the given string. 00043 Returns a new ClassAd or null if the input is invalid or memory is full. 00044 */ 00045 00046 struct cclassad * cclassad_create( const char *str ); 00047 void cclassad_delete( struct cclassad *c ); 00048 00049 /* 00050 Display a ClassAd in its external representation. 00051 Returns a string allocated with malloc(). 00052 The user is responsible for freeing it. 00053 */ 00054 00055 char * cclassad_unparse( struct cclassad *c ); 00056 char * cclassad_unparse_xml( struct cclassad *c ); 00057 00058 /* 00059 Check to see if two ClassAds match. 00060 Return true if their requirements expressions are 00061 mutually satisfied. Otherwise, return false. 00062 */ 00063 00064 int cclassad_match( struct cclassad *a, struct cclassad *b ); 00065 00066 /* 00067 Four ways to insert elements into a classad. 00068 In each case, "attr" names the attribute to be 00069 inserted. In the "expr" form, the "value" must be a ClassAd 00070 expression which is parsed and then inserted. 00071 The remaining forms insert atomic types without parsing. 00072 Returns true on success, false on failure. 00073 */ 00074 00075 int cclassad_insert_expr( struct cclassad *c, const char *attr, const char *value ); 00076 int cclassad_insert_string( struct cclassad *c, const char *attr, const char *value ); 00077 int cclassad_insert_double( struct cclassad *c, const char *attr, double value ); 00078 int cclassad_insert_int( struct cclassad *c, const char *attr, int value ); 00079 int cclassad_insert_bool( struct cclassad *c, const char *attr, int value ); 00080 00081 /* 00082 Remove the named element from the ClassAd. 00083 Returns true if the attribute existed, false otherwise. 00084 */ 00085 00086 int cclassad_remove( struct cclassad *c, const char *attr ); 00087 00088 /* 00089 Four ways to evaluate the contents of a classad. 00090 In each case, "expr" is an expression to be parsed and evaluted. 00091 In the "to_expr" form, the result is given as an expression in 00092 external form allocated with malloc(). The caller must free() it. 00093 In the remaining forms, the results are given as atomic values 00094 that need not be parsed. Returns true on success, false on failure. 00095 */ 00096 00097 int cclassad_evaluate_to_expr( struct cclassad *c, const char *expr, char **result ); 00098 int cclassad_evaluate_to_string( struct cclassad *c, const char *expr, char **result ); 00099 int cclassad_evaluate_to_double( struct cclassad *c, const char *expr, double *result ); 00100 int cclassad_evaluate_to_int( struct cclassad *c, const char *expr, int *result ); 00101 int cclassad_evaluate_to_bool( struct cclassad *c, const char *expr, int *result ); 00102 00103 #ifdef __cplusplus 00104 } 00105 END_NAMESPACE 00106 #endif 00107 00108 #endif