From 6c8389fee30016ececb5688696e1bf54a1f00e12 Mon Sep 17 00:00:00 2001 From: Niels Grewe Date: Mon, 6 Jan 2014 14:55:35 +0000 Subject: [PATCH] Regenerate README, improve protability of a few string formats, implement method for marshalling the contents of a notification's user info dictionary for use as in-arguments of a D-Bus signal. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/dbuskit/trunk@37543 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 11 +++++++++++ README | 6 +++--- Source/DKEndpointManager.m | 6 +++--- Source/DKInterface.m | 2 +- Source/DKSignal.h | 18 ++++++++++++++++++ Source/DKSignal.m | 29 +++++++++++++++++++++++++++++ 6 files changed, 65 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5891c07..ec9d7a8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2014-01-06 Niels Grewe + * README: Regenerate + * Source/DKEndpointManager.m + * Source/DKInterface.m: + Format string safety improvements. + * Source/DKSignal.h + * Source/DKSignal.m: + Add method to marshall the contents of a notification's + user info dictionary into D-Bus wire format. + + 2014-01-05 Niels Grewe * Bundles/DBusMenu/DKMenuRegistry.m: diff --git a/README b/README index 1c0963b..9204707 100644 --- a/README +++ b/README @@ -35,8 +35,8 @@ improvements you have made freely available. You should read the COPYING file in the root directory of the framework distribution for more information. The file `Source/type_encoding_cases.h' is originally part of the GNUstep Objective-C runtime and licensed under the MIT -license. All other files in the `Source', `Headers', and `Tests' -directories are covered under the LGPL. +license. All other files in the `Bundles', `Source', `Headers', and +`Tests' directories are covered under the LGPL. The associated tools and examples are covered under the GNU Public License. This means if you make changes to these programs, you cannot @@ -48,7 +48,7 @@ GPL. The documentation is, unless noted otherwise, licensed under the GNU Free Documentation License (with no Invariant Sections or Cover Texts). - Copyright (C) 2010 Free Software Foundation + Copyright (C) 2010-2014 Free Software Foundation Copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright diff --git a/Source/DKEndpointManager.m b/Source/DKEndpointManager.m index d7f9e9e..b0a7223 100644 --- a/Source/DKEndpointManager.m +++ b/Source/DKEndpointManager.m @@ -142,7 +142,7 @@ if (NO == DKRingEmpty)\ __sync_fetch_and_add(&producerCounter, 1);\ [producerLock unlock];\ NSDebugMLog(@"Inserting into ringbuffer (remaining capacity: %lu).",\ - DKRingSpace);\ + (unsigned long)DKRingSpace);\ } while (0) @@ -152,14 +152,14 @@ if (NO == DKRingEmpty)\ #define DKRingRemove(x) do {\ if (NO == DKRingEmpty)\ {\ - NSDebugMLog(@"Removing element at %lu from ring buffer", DKMaskIndex(consumerCounter));\ + NSDebugMLog(@"Removing element at %lu from ring buffer", (unsigned long)DKMaskIndex(consumerCounter));\ x = ringBuffer[DKMaskIndex(consumerCounter)];\ ringBuffer[DKMaskIndex(consumerCounter)] = (DKRingBufferElement){nil, NULL, nil, NULL};\ [x.target autorelease];\ __sync_fetch_and_add(&consumerCounter, 1);\ }\ NSDebugMLog(@"(new capacity: %lu).",\ - DKRingSpace);\ + (unsigned long)DKRingSpace);\ } while (0) @implementation DKEndpointManager diff --git a/Source/DKInterface.m b/Source/DKInterface.m index 2063d5c..ef25579 100644 --- a/Source/DKInterface.m +++ b/Source/DKInterface.m @@ -307,7 +307,7 @@ if (NULL == selectorString) { - NSWarnMLog(@"Cannot register selector with empty name for method %@"); + NSWarnMLog(@"Cannot register selector with empty name for method %@", aMethod); return; } diff --git a/Source/DKSignal.h b/Source/DKSignal.h index d36aed3..98a3ec5 100644 --- a/Source/DKSignal.h +++ b/Source/DKSignal.h @@ -68,6 +68,24 @@ */ - (NSDictionary*)userInfoFromIterator: (DBusMessageIter*)iter; + +/** + * Marshalls the arguments from an NSNotification's userInfo dictionary into + * a libdbus iterator. The algorithm for resolving the values is as follows: + * + * 1. If an argument has an attached org.gnustep.openstep.notification.key + * annotation, get the value for that key. + * 2. If the value is nil, try the argN key of the dictionary, where argN + * is the position of the argument in the introspection graph + * 3. Marshall the value into the iterator. + * + * As a consequence, named arguments take precedence over positional ones, + * and absence is interpreted as a null value, which may cause an exception + * for some data types (e.g. object paths) + */ +- (void)marshallUserInfo: (NSDictionary*)userInfo + intoIterator: (DBusMessageIter*)iter; + /** * Returns YES if the signal is a stub signal created by the notification * center. diff --git a/Source/DKSignal.m b/Source/DKSignal.m index 5d12c13..51c3c0e 100644 --- a/Source/DKSignal.m +++ b/Source/DKSignal.m @@ -168,6 +168,35 @@ return userInfo; } +- (void)marshallUserInfo: (NSDictionary*)userInfo + intoIterator: (DBusMessageIter*)iter +{ + NSUInteger numArgs = [args count]; + NSUInteger index = 0; + while (index < (numArgs)) + { + NSString *key = [NSString stringWithFormat: @"arg%lu", index]; + DKArgument *arg = (DKArgument*)[args objectAtIndex: index]; + NSString *annotatedKey = [arg annotationValueForKey: @"org.gnustep.openstep.notification.key"]; + + id value = nil; + if (nil != annotatedKey) + { + value = [userInfo objectForKey: annotatedKey]; + } + + if (nil == value) + { + // second try, with the argN key + value = [userInfo objectForKey: key]; + } + [arg marshallObject: value + intoIterator: iter]; + index++; + } +} + + - (NSXMLNode*)XMLNode { NSXMLNode *nameAttribute = [NSXMLNode attributeWithName: @"name"