[darwinbuild-changes] [186] trunk/darwinxref

source_changes at macosforge.org source_changes at macosforge.org
Wed Oct 4 01:55:36 PDT 2006


Revision: 186
          http://trac.macosforge.org/projects/darwinbuild/changeset/186
Author:   ssen
Date:     2006-10-04 01:55:36 -0700 (Wed, 04 Oct 2006)

Log Message:
-----------
Add the concept of a "SubDict" data type specification. Plugins
which declare plist property types as dictionary types (like "environment",
"dependencies") can require that the values be arrays, even
if there is only one value. Now that I look at this, this is really
poorly named. Will need to revise.

Modified Paths:
--------------
    trunk/darwinxref/DBDataStore.c
    trunk/darwinxref/DBPlugin.c
    trunk/darwinxref/DBPlugin.h
    trunk/darwinxref/DBPluginPriv.h

Modified: trunk/darwinxref/DBDataStore.c
===================================================================
--- trunk/darwinxref/DBDataStore.c	2005-08-20 06:52:48 UTC (rev 185)
+++ trunk/darwinxref/DBDataStore.c	2006-10-04 08:55:36 UTC (rev 186)
@@ -144,10 +144,23 @@
 	if (name) {
 		CFTypeRef cf = CFDictionaryGetValue(dict, name);
 		if (cf == NULL) {
-			CFDictionarySetValue(dict, name, value);
-		} else if (CFGetTypeID(cf) == CFStringGetTypeID()) {
+		  CFDictionaryAddValue(dict, name, value);
+		}
+		CFRelease(name);
+	}
+	CFRelease(value);
+	return 0;
+}
+
+static int sqlAddArrayValueToDictionary(void* pArg, int argc, char **argv, char** columnNames) {
+	CFMutableDictionaryRef dict = pArg;
+	CFStringRef name = cfstr(argv[0]);
+	CFStringRef value = cfstr(argv[1]);
+	if (!value) value = CFRetain(CFSTR(""));
+	if (name) {
+		CFTypeRef cf = CFDictionaryGetValue(dict, name);
+		if (cf == NULL) {
 			CFMutableArrayRef array = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
-			CFArrayAppendValue(array, cf);
 			CFArrayAppendValue(array, value);
 			CFDictionarySetValue(dict, name, array);
 			CFRelease(array);
@@ -167,6 +180,13 @@
 	return dict;
 }
 
+CFDictionaryRef SQL_CFDICTIONARY_OFCFARRAYS(const char* fmt, ...) {
+	int res;
+	CFMutableDictionaryRef dict = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
+	__SQL(sqlAddArrayValueToDictionary, dict, fmt);
+	return dict;
+}
+
 void SQL_NOERR(char* sql) {
 	char* errmsg;
 	sqlite3* db = _DBPluginGetDataStorePtr();
@@ -255,6 +275,15 @@
 	return type;
 }
 
+CFTypeID  DBCopyPropSubDictType(CFStringRef property) {
+	CFTypeID type = -1;
+	const DBPlugin* plugin = DBGetPluginWithName(property);
+	if (plugin && plugin->type == kDBPluginPropertyType) {
+		type = plugin->subdictdatatype;
+	}
+	return type;
+}
+
 CFTypeRef DBCopyProp(CFStringRef build, CFStringRef project, CFStringRef property) {
 	CFTypeRef res = NULL;
 	CFTypeID type = DBCopyPropType(property);
@@ -310,12 +339,19 @@
 	char* cbuild = strdup_cfstr(build);
 	char* cproj = strdup_cfstr(project);
 	char* cprop = strdup_cfstr(property);
+	CFTypeID subtype = DBCopyPropSubDictType(property);
 	char* sql;
 	if (cproj && *cproj != 0)
 		sql = "SELECT DISTINCT key,value FROM properties WHERE property=%Q AND build=%Q AND project=%Q ORDER BY key";
 	else
 		sql = "SELECT DISTINCT key,value FROM properties WHERE property=%Q AND build=%Q AND project IS NULL ORDER BY key";
-	CFDictionaryRef res = SQL_CFDICTIONARY(sql, cprop, cbuild, cproj);
+	CFDictionaryRef res;
+
+	if(subtype == CFArrayGetTypeID())
+	  res = SQL_CFDICTIONARY_OFCFARRAYS(sql, cprop, cbuild, cproj);
+	else
+	  res = SQL_CFDICTIONARY(sql, cprop, cbuild, cproj);
+
 	if (res && CFDictionaryGetCount(res) == 0) {
 		CFRelease(res);
 		res = NULL;

Modified: trunk/darwinxref/DBPlugin.c
===================================================================
--- trunk/darwinxref/DBPlugin.c	2005-08-20 06:52:48 UTC (rev 185)
+++ trunk/darwinxref/DBPlugin.c	2006-10-04 08:55:36 UTC (rev 186)
@@ -78,8 +78,13 @@
 	plugin->datatype = type;
 }
 
+void DBPluginSetSubDictDataType(CFTypeID type) {
+	DBPlugin* plugin = _DBPluginGetCurrentPlugin();
+	plugin->subdictdatatype = type;
+}
 
 
+
 //////
 // Private interfaces to DBPlugin for use by darwinxref internals
 //////

Modified: trunk/darwinxref/DBPlugin.h
===================================================================
--- trunk/darwinxref/DBPlugin.h	2005-08-20 06:52:48 UTC (rev 185)
+++ trunk/darwinxref/DBPlugin.h	2006-10-04 08:55:36 UTC (rev 186)
@@ -122,6 +122,7 @@
 void DBPluginSetRunFunc(DBPluginRunFunc func);
 void DBPluginSetUsageFunc(DBPluginUsageFunc func);
 void DBPluginSetDataType(CFTypeID type);
+void DBPluginSetSubDictDataType(CFTypeID type);
 
 // generally available routines
 
@@ -130,6 +131,7 @@
 CFArrayRef DBCopyBuilds();
 
 CFTypeID  DBCopyPropType(CFStringRef property);
+CFTypeID  DBCopyPropSubDictType(CFStringRef property);
 CFArrayRef DBCopyPropNames(CFStringRef build, CFStringRef project);
 CFArrayRef DBCopyProjectNames(CFStringRef build);
 

Modified: trunk/darwinxref/DBPluginPriv.h
===================================================================
--- trunk/darwinxref/DBPluginPriv.h	2005-08-20 06:52:48 UTC (rev 185)
+++ trunk/darwinxref/DBPluginPriv.h	2006-10-04 08:55:36 UTC (rev 186)
@@ -44,6 +44,8 @@
 	for this plugin.
 	@field datatype The datatype of this property
 	(i.e. one of CFStringGetTypeID(), CFArrayGetTypeID(), CFDictionaryGetTypeID())
+	@field subdictdatatype For dictionary data types, force values to be
+	this type (i.e. CFArrayGetTypeID())
 	@field getprop The property get accessor, NULL for default behavior
 	@field setprop The property set accessor, NULL for default behavior
 */
@@ -60,6 +62,7 @@
 #endif
 	// for property plugins
 	CFTypeID	datatype;
+	CFTypeID	subdictdatatype;
 //	DBPluginGetPropFunc getprop;
 //	DBPluginSetPropFunc setprop;
 };

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/darwinbuild-changes/attachments/20061004/8e1e0062/attachment.html


More information about the darwinbuild-changes mailing list