Darling build

This commit is contained in:
Sergey Bugaev 2020-04-16 14:38:18 +03:00
parent 624d5899f3
commit 399f8bcb76
25 changed files with 505 additions and 7 deletions

1
.gitignore vendored
View File

@ -18,5 +18,4 @@ config.log
config.make
config.status
libtool
Source/config.h
autom4te.cache

56
CMakeLists.txt Normal file
View File

@ -0,0 +1,56 @@
project(DBusKit)
include(darling_framework)
find_package(PkgConfig REQUIRED)
pkg_check_modules(PC_DBUS dbus-1)
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/include
${PC_DBUS_INCLUDE_DIRS}
)
set(DBusKit_sources
Source/DKArgument.m
Source/DKBoxingUtils.m
Source/DKEndpoint.m
Source/DKEndpointManager.m
Source/DKInterface.m
Source/DKIntrospectionNode.m
Source/DKIntrospectionParserDelegate.m
Source/DKMessage.m
Source/DKMethodCall.m
Source/DKMethod.m
Source/DKMethodReturn.m
Source/DKNonAutoInvalidatingPort.m
Source/DKNotificationCenter.m
Source/DKNumber.m
Source/DKObjectPathNode.m
Source/DKOutgoingProxy.m
Source/DKPort.m
Source/DKPortNameServer.m
Source/DKProperty.m
Source/DKPropertyMethod.m
Source/DKProxy.m
Source/DKSignalEmission.m
Source/DKSignal.m
Source/DKStruct.m
Source/DKVariant.m
# Source/NSConnection+DBus.m
Source/DKConnection.m
)
add_framework(DBusKit
FAT
CURRENT_VERSION
PRIVATE
SOURCES
${DBusKit_sources}
VERSION "A"
DEPENDENCIES
objc
system
Foundation
# native libraries
dbus
)

View File

@ -26,4 +26,9 @@
#import <DBusKit/DKProxy.h>
#import <DBusKit/DKStruct.h>
#import <DBusKit/DKVariant.h>
#ifndef DARLING
#import <DBusKit/NSConnection+DBus.h>
#else
#import <DBusKit/DKConnection.h>
#endif

69
Headers/DKConnection.h Normal file
View File

@ -0,0 +1,69 @@
/*
This file is part of Darling.
Copyright (C) 2020 Lubos Dolezel
Darling is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Darling is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Darling. If not, see <http://www.gnu.org/licenses/>.
*/
/** Category on NSConnection to facilitate D-Bus integration
Copyright (C) 2010 Free Software Foundation, Inc.
Written by: Niels Grewe <niels.grewe@halbordnung.de>
Created: July 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02111 USA.
*/
#import <Foundation/NSConnection.h>
@class DKProxy, DKPort, NSString;
@interface DKConnection: NSConnection
/**
* Returns a proxy to D-Bus object located at the specified D-Bus object path.
* Will return <code>nil</code> if used for native DO connections.
*/
- (DKProxy*)proxyAtPath: (NSString*)path;
/**
* Vends the named <var>object</var> at the specified D-Bus object
* <var>path</var>. Users should note that the registered names of a D-Bus port
* do not act as namespaces for object paths. It is thus advisable not to use
* the root path "/" to export objects.
*
* For native DO connections this method is only effective if the
* <var>path</var> is "/", in which case it is equivalent to calling
* -rootObject:.
*/
- (void)setObject: (id)object
atPath: (NSString*)path;
@end

View File

@ -39,7 +39,9 @@
#import <Foundation/NSValue.h>
#import <Foundation/NSXMLNode.h>
#ifndef DARLING
#import <GNUstepBase/NSDebug+GNUstepBase.h>
#endif
#import "DKProxy+Private.h"
#import "DKPort+Private.h"
@ -1581,9 +1583,9 @@ DKDBusTypeForUnboxingObject(id object)
- (void) setIsDictionary: (BOOL)isDict
{
# ifndef NDEBUG
#if !defined(NDEBUG) && !defined(DARLING)
GSDebugAllocationRemove(object_getClass(self), self);
# endif
#endif
if (isDict)
{
object_setClass(self,[DKDictionaryTypeArgument class]);
@ -1595,7 +1597,7 @@ DKDBusTypeForUnboxingObject(id object)
object_setClass(self,[DKArrayTypeArgument class]);
[self setObjCEquivalent: [NSArray class]];
}
#ifndef NDEBUG
#if !defined(NDEBUG) && !defined(DARLING)
GSDebugAllocationAdd(object_getClass(self), self);
#endif
}

View File

@ -35,7 +35,9 @@
#import <Foundation/NSFileHandle.h>
#import <Foundation/NSValue.h>
#ifndef DARLING
#import <GNUstepBase/Unicode.h>
#endif
#include <dbus/dbus.h>
#include <wctype.h>
@ -570,7 +572,11 @@ DKMethodNameFromSelectorString(const char* selString)
i++;
if (iswlower(heapChars[i]))
{
#ifndef DARLING
heapChars[i] = uni_toupper(heapChars[i]);
#else
heapChars[i] = toupper(heapChars[i]);
#endif
}
}
}

85
Source/DKConnection.m Normal file
View File

@ -0,0 +1,85 @@
/*
This file is part of Darling.
Copyright (C) 2020 Lubos Dolezel
Darling is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Darling is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Darling. If not, see <http://www.gnu.org/licenses/>.
*/
/** Category on NSConnection to facilitate D-Bus integration
Copyright (C) 2010 Free Software Foundation, Inc.
Written by: Niels Grewe <niels.grewe@halbordnung.de>
Created: July 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02111 USA.
*/
#import "DBusKit/DKConnection.h"
#import "DBusKit/DKPort.h"
#import "DKProxy+Private.h"
@interface DKPort (DKPortPrivate)
- (BOOL)hasValidRemote;
- (void)_setObject: (id)obj
atPath: (NSString*)path;
@end
@implementation DKConnection
- (NSDistantObject *)rootProxy
{
return (NSDistantObject*)[self proxyAtPath: @"/"];
}
- (void)setRootObject: (id)obj
{
[self setObject: obj
atPath: @"/"];
}
- (void)setObject: (id)obj
atPath: (NSString*)path
{
id rp = [self receivePort];
[(DKPort*)rp _setObject: obj
atPath: path];
}
- (DKProxy*)proxyAtPath: (NSString*)path
{
id sp = [self sendPort];
if (NO == [sp hasValidRemote])
{
return nil;
}
return [DKProxy proxyWithPort: sp
path: path];
}
@end

View File

@ -35,7 +35,14 @@
#import <Foundation/NSTimer.h>
#import <Foundation/NSValue.h>
#import <Foundation/NSPortCoder.h>
#ifndef DARLING
#import <GNUstepBase/NSDebug+GNUstepBase.h>
#else
#import "config.h"
#import <CoreFoundation/CFSocket.h>
#import <CoreFoundation/CFRunLoop.h>
#endif
#import "DBusKit/DKPort.h"
#import "DKEndpointManager.h"
@ -108,6 +115,7 @@ DKRelease(void *ptr);
- (NSString*)runLoopMode;
@end
#ifndef DARLING
/**
* Watcher object to monitor the file descriptors D-Bus signals on.
*/
@ -120,6 +128,20 @@ DKRelease(void *ptr);
}
@end
#else
@interface DKWatcher: NSObject
{
DBusWatch *watch;
BOOL callbackInProgress;
DKRunLoopContext *ctx;
CFSocketRef socket;
CFRunLoopSourceRef source;
}
@end
#endif
@implementation DKEndpoint
@ -467,6 +489,8 @@ DKRelease(void *ptr);
@end
@implementation DKWatcher
#ifndef DARLING
/**
* Tells the run loop to monitor the events that D-Bus wants to monitor.
*/
@ -514,6 +538,41 @@ DKRelease(void *ptr);
}
#else
- (void)monitorForEvents
{
CFRunLoopRef cfRunLoop = [[ctx runLoop] getCFRunLoop];
CFRunLoopAddSource(cfRunLoop, source, (CFStringRef) [ctx runLoopMode]);
}
- (void)unmonitorForEvents
{
CFRunLoopRef cfRunLoop = [[ctx runLoop] getCFRunLoop];
CFRunLoopRemoveSource(cfRunLoop, source, (CFStringRef) [ctx runLoopMode]);
}
static void DKSocketCallback(
CFSocketRef socket,
CFSocketCallBackType callbackType,
CFDataRef address,
const void *data,
void *info
) {
DKWatcher *self = (DKWatcher *) info;
if (callbackType == kCFSocketReadCallBack)
{
dbus_watch_handle(self->watch, DBUS_WATCH_READABLE);
}
else
{
dbus_watch_handle(self->watch, DBUS_WATCH_WRITABLE);
}
}
#endif
- (id)initWithWatch: (DBusWatch*)_watch
andContext: (DKRunLoopContext*)aCtx
forFd: (int)fd
@ -522,7 +581,23 @@ DKRelease(void *ptr);
{
return nil;
}
#ifndef DARLING
fileDesc = fd;
#else
CFSocketCallBackType callbackType = 0;
NSUInteger events = dbus_watch_get_flags(_watch);
if (events & DBUS_WATCH_READABLE)
{
callbackType |= kCFSocketReadCallBack;
}
if (events & DBUS_WATCH_WRITABLE)
{
callbackType |= kCFSocketWriteCallBack;
}
CFSocketContext context = { .info = self };
socket = CFSocketCreateWithNative(NULL, fd, callbackType, DKSocketCallback, &context);
source = CFSocketCreateRunLoopSource(NULL, socket, 0);
#endif
// The context retains its watchers and timers:
ctx = aCtx;
watch = _watch;
@ -531,6 +606,7 @@ DKRelease(void *ptr);
}
#ifndef DARLING
/**
* Delegate method for event delivery by the run loop.
*/
@ -561,6 +637,7 @@ DKRelease(void *ptr);
}
callbackInProgress = NO;
}
#endif
- (void)dealloc
{
@ -569,6 +646,7 @@ DKRelease(void *ptr);
* cannot ask libdbus what kind of event we were watching for. Hence, we
* remove ourselves from the loop for all event types.
*/
#ifndef DARLING
[[ctx runLoop] removeEvent: (void*)(intptr_t)fileDesc
type: ET_RDESC
forMode: [ctx runLoopMode]
@ -577,6 +655,18 @@ DKRelease(void *ptr);
type: ET_WDESC
forMode: [ctx runLoopMode]
all: NO];
#else
if (source != NULL)
{
CFRelease(source);
}
if (socket != NULL)
{
// FIXME: does this close the fd? should it?
CFSocketInvalidate(socket);
CFRelease(socket);
}
#endif
[super dealloc];
}
@end

View File

@ -53,8 +53,10 @@
* classes here inherit from NSObject, so that we can call +alloc -init on them
* in order to initialize them before starting the worker thread.
*/
#ifndef DARLING
@interface GSStackTrace : NSObject @end
@interface DKWatcher : NSObject <RunLoopEvents> @end
#endif
@interface DKWatcher : NSObject @end
@interface DKEndpoint (Private)
- (void)_mergeInfo: (NSDictionary*)info;
@ -193,7 +195,9 @@ if (NO == DKRingEmpty)\
* NOTE: This only works properly if we send instance methods (maybe
* because the meta-class gets initialized otherwise?).
*/
#ifndef DARLING
[[[GSStackTrace alloc] init] release];
#endif
[[[NSException alloc] init] release];
[[[NSTimer alloc] init] release];
[[[DKWatcher alloc] init] release];

View File

@ -28,7 +28,9 @@
#import <Foundation/NSXMLNode.h>
#import <Foundation/NSXMLParser.h>
#ifndef DARLING
#import <GNUstepBase/NSDebug+GNUstepBase.h>
#endif
#define INCLUDE_RUNTIME_H
#include "config.h"

View File

@ -35,6 +35,10 @@
#import <Foundation/NSXMLNode.h>
#import <Foundation/NSXMLParser.h>
#ifdef DARLING
#import "config.h"
#endif
@implementation DKIntrospectionNode
- (id) initWithName: (NSString*)aName

View File

@ -27,7 +27,12 @@
#import "DKEndpoint.h"
#include <dbus/dbus.h>
#ifndef DARLING
#import <GNUstepBase/NSDebug+GNUstepBase.h>
#else
#import "config.h"
#endif
@implementation DKMessage

View File

@ -36,7 +36,11 @@
#import <Foundation/NSString.h>
#import <Foundation/NSThread.h>
#ifndef DARLING
#import <GNUstepBase/NSDebug+GNUstepBase.h>
#else
#import "config.h"
#endif
#include <sched.h>
#include <string.h>

View File

@ -30,7 +30,12 @@
#import "DKEndpointManager.h"
#import <Foundation/NSException.h>
#import <Foundation/NSInvocation.h>
#ifndef DARLING
#import <GNUstepBase/NSDebug+GNUstepBase.h>
#else
#import "config.h"
#endif
#include <dbus/dbus.h>
@implementation DKMethodReturn

View File

@ -46,7 +46,12 @@
#import <Foundation/NSSet.h>
#import <Foundation/NSString.h>
#import <Foundation/NSValue.h>
#ifndef DARLING
#import <GNUstepBase/NSDebug+GNUstepBase.h>
#else
#import "config.h"
#endif
#include <inttypes.h>
#include <stdint.h>

View File

@ -33,7 +33,12 @@
#import <Foundation/NSInvocation.h>
#import <Foundation/NSString.h>
#import <Foundation/NSXMLNode.h>
#ifndef DARLING
#import <GNUstepBase/NSDebug+GNUstepBase.h>
#else
#import "config.h"
#endif
@implementation DKObjectPathNode

View File

@ -39,7 +39,11 @@
#import <Foundation/NSXMLNode.h>
#import <Foundation/NSPathUtilities.h>
#ifndef DARLING
#import <GNUstepBase/NSDebug+GNUstepBase.h>
#else
#import "config.h"
#endif
#if __OBJC_GC__
#import <Foundation/NSGarbageCollector.h>

View File

@ -49,6 +49,7 @@
#include <dbus/dbus.h>
#ifndef DARLING
/*
* Enumeration of GNUstep DO message IDs, will need to be kept in sync with
* GNUstepBase/DistributedObjects.h.
@ -68,6 +69,7 @@ enum {
PROXY_AT_PATH_REQUEST = 254,
PROXY_AT_PATH_REPLY = 255
};
#endif
@protocol DBus
- (NSArray*)ListNames;
@ -410,6 +412,7 @@ static DKPort *sharedSystemPort;
return ([endpoint hash] ^ [remote hash]);
}
#ifndef DARLING
/**
* This is the main method used to dispatch stuff from the DO system to D-Bus.
* Primarily we want to respond to ROOTPROXY_REQUEST, because everyting else
@ -527,6 +530,7 @@ static DKPort *sharedSystemPort;
*count=0;
}
}
#endif
/**
* Required for NSPort compatibility.
@ -536,6 +540,13 @@ static DKPort *sharedSystemPort;
return 0;
}
#ifdef DARLING
- (void)scheduleInRunLoop: (NSRunLoop *) runLoop
forMode: (NSRunLoopMode) mode
{
}
#endif
- (void)_cleanupExportedObjects
{
[objectPathLock lock];
@ -589,6 +600,8 @@ static DKPort *sharedSystemPort;
{
[self invalidate];
}
#ifndef DARLING
/**
* Performs checks to ensure that the corresponding D-Bus service and object
* path exist and sends a message to the delegate NSConnection object containing
@ -657,6 +670,7 @@ static DKPort *sharedSystemPort;
[proxyCoder release];
return YES;
}
#endif
/*

View File

@ -30,7 +30,12 @@
#import <Foundation/NSInvocation.h>
#import <Foundation/NSMethodSignature.h>
#import <Foundation/NSString.h>
#ifndef DARLING
#import <GNUstepBase/NSDebug+GNUstepBase.h>
#else
#import "config.h"
#endif
#include <string.h>
#include <dbus/dbus.h>

View File

@ -53,8 +53,11 @@
#import <Foundation/NSXMLNode.h>
#import <Foundation/NSXMLParser.h>
#import <Foundation/NSPathUtilities.h>
#ifndef DARLING
#import <GNUstepBase/GSObjCRuntime.h>
#import <GNUstepBase/NSDebug+GNUstepBase.h>
#endif
#include <string.h>
@ -480,13 +483,14 @@ NSString *kDKDBusDocType = @"<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS O
* the signature from the associated method.
*/
DKMethod *method = [self DBusMethodForSelector: aSelector];
#ifndef DARLING
const char *types = NULL;
NSMethodSignature *theSig = nil;
types = GSTypesFromSelector(aSelector);
// Build a signature with the types:
theSig = [NSMethodSignature signatureWithObjCTypes: types];
#endif
/*
* Second chance to find the method: Remove mangling constructs from the
* selector string.
@ -516,7 +520,7 @@ NSString *kDKDBusDocType = @"<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS O
}
}
#ifndef DARLING
// Finally check whether we have a sensible method and signature:
if (nil == method)
{
@ -539,6 +543,9 @@ NSString *kDKDBusDocType = @"<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS O
}
return nil;
#else
return [method methodSignature];
#endif
}
/**
@ -661,7 +668,18 @@ NSString *kDKDBusDocType = @"<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS O
- (BOOL)isKindOfClass: (Class)aClass
{
#ifndef DARLING
return GSObjCIsKindOf([self class], aClass);
#else
for (Class cls = object_getClass(self); cls; cls = class_getSuperclass(cls))
{
if (cls == aClass)
{
return YES;
}
}
return NO;
#endif
}
- (DKPort*)_port

View File

@ -30,7 +30,12 @@
#import "DKEndpointManager.h"
#import <Foundation/NSException.h>
#import <Foundation/NSInvocation.h>
#ifndef DARLING
#import <GNUstepBase/NSDebug+GNUstepBase.h>
#else
#import "config.h"
#endif
#include <dbus/dbus.h>

View File

@ -22,6 +22,10 @@
#import "DBusKit/DKStruct.h"
#ifdef DARLING
#import "config.h"
#endif
@implementation NSArray (DBusKit)
- (BOOL)isDBusStruct
{

View File

@ -26,6 +26,10 @@
#import <Foundation/NSLocale.h>
#import <Foundation/NSString.h>
#ifdef DARLING
#import "config.h"
#endif
#include <string.h>
@implementation DKVariant

97
Source/config.h Normal file
View File

@ -0,0 +1,97 @@
/** Configuration dependent information for DBusKit.
Copyright (C) 2010 Free Software Foundation, Inc.
Written by: Niels Grewe <niels.grewe@halbordnung.de>
Created: June 2010
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02111 USA.
*/
/*
* Correct location of runtime.h, if requested.
*/
// #ifdef INCLUDE_RUNTIME_H
# include <objc/runtime.h>
// #endif
/*
#ifndef HAVE_OBJC_ENCODING_H
# define HAVE_OBJC_ENCODING_H @HAVE_OBJC_ENCODING_H@
#endif
#ifndef USE_SEL_GETTYPEENCODING
# define USE_SEL_GETTYPEENCODING @USE_SEL_GETTYPEENCODING@
# if USE_SEL_GETTYPEENCODING
# define sel_getType_np sel_getTypeEncoding
# endif
#endif
*/
#ifndef DISABLE_TYPED_SELECTORS
# define DISABLE_TYPED_SELECTORS 1
#endif
#ifndef HAVE_LIBCLANG
# define HAVE_LIBCLANG 0
#endif
#ifndef HAVE_FUNC_ATTRIBUTE_VISIBILITY
# define HAVE_FUNC_ATTRIBUTE_VISIBILITY 1
#endif
// For Darling build
#if 0
#define NSDebugLog NSLog
#define NSDebugMLog NSLog
#define NSDebugFLog NSLog
#define NSWarnMLog NSLog
#define GSOnceMLog NSLog
#else
#define NSDebugLog(...)
#define NSDebugMLog(...)
#define NSDebugFLog(...)
#define NSWarnMLog(...)
#define GSOnceMLog(...)
#endif
#define objc_skip_argspec(types) NSGetSizeAndAlignment(types, NULL, NULL)
static inline const char *objc_skip_type_qualifiers(const char *types) {
for (;; types++) {
switch (types[0]) {
case 'r':
case 'n':
case 'N':
case 'o':
case 'O':
case 'R':
case 'V':
break;
default:
return types;
}
}
}
#import <CoreFoundation/GNUstep.h>
@interface NSObject (Responsibility)
- (void) subclassResponsibility: (SEL) selector;
- (void) shouldNotImplement: (SEL) selector;
@end

1
include/DBusKit Symbolic link
View File

@ -0,0 +1 @@
../Headers/