~ubuntu-branches/ubuntu/trusty/gnustep-base/trusty

« back to all changes in this revision

Viewing changes to Tools/gdnc.m

Tags: upstream-1.20.0
ImportĀ upstreamĀ versionĀ 1.20.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/** Implementation of GNUstep Distributed Notification Center
2
 
   Copyright (C) 1998 Free Software Foundation, Inc.
 
1
/* Copyright (C) 1998 Free Software Foundation, Inc.
3
2
 
4
3
   Written by:  Richard Frith-Macdonald <richard@brainstorm.co.uk>
5
4
   Created: October 1998
18
17
 
19
18
   */
20
19
 
21
 
#include        "config.h"
22
 
#include        <Foundation/Foundation.h>
23
 
 
24
 
#include        <stdio.h>
25
 
#include        <unistd.h>
26
 
 
27
 
#if     defined(__MINGW32__)
 
20
#import "common.h"
 
21
 
 
22
#include <stdio.h>
 
23
#include <unistd.h>
 
24
 
 
25
#import "Foundation/NSArray.h"
 
26
#import "Foundation/NSAutoreleasePool.h"
 
27
#import "Foundation/NSBundle.h"
 
28
#import "Foundation/NSConnection.h"
 
29
#import "Foundation/NSData.h"
 
30
#import "Foundation/NSDistantObject.h"
 
31
#import "Foundation/NSDistributedNotificationCenter.h"
 
32
#import "Foundation/NSException.h"
 
33
#import "Foundation/NSHashTable.h"
 
34
#import "Foundation/NSHost.h"
 
35
#import "Foundation/NSNotification.h"
 
36
#import "Foundation/NSPort.h"
 
37
#import "Foundation/NSPortNameServer.h"
 
38
#import "Foundation/NSProcessInfo.h"
 
39
#import "Foundation/NSRunLoop.h"
 
40
#import "Foundation/NSTask.h"
 
41
#import "Foundation/NSUserDefaults.h"
 
42
 
 
43
 
 
44
#if     defined(__MINGW__)
28
45
#include        "process.h"
29
46
#endif
30
47
 
42
59
static BOOL     debugging = NO;
43
60
static BOOL     is_daemon = NO;         /* Currently running as daemon.  */
44
61
static BOOL     auto_stop = NO;         /* Should we shut down when unused? */
45
 
static char     ebuf[2048];
46
62
 
47
63
#ifdef HAVE_SYSLOG
48
64
 
49
65
static int      log_priority = LOG_DEBUG;
50
66
 
51
67
static void
52
 
gdnc_log (int prio)
 
68
gdnc_log (int prio, const char *ebuf)
53
69
{
54
70
  if (is_daemon)
55
71
    {
56
 
      syslog (log_priority | prio, ebuf);
 
72
      syslog (log_priority | prio, "%s", ebuf);
57
73
    }
58
74
  else if (prio == LOG_INFO)
59
75
    {
87
103
#define LOG_ERR         1
88
104
#define LOG_INFO        0
89
105
#define LOG_WARNING     0
90
 
void
91
 
gdnc_log (int prio)
 
106
static void
 
107
gdnc_log (int prio, const char *ebuf)
92
108
{
93
109
  write (2, ebuf, strlen (ebuf));
94
110
  write (2, "\n", 1);
161
177
                              object: (NSString*)object
162
178
                            userInfo: (NSData*)info
163
179
                            selector: (NSString*)aSelector
164
 
                                  to: (NSUInteger)observer;
 
180
                                  to: (uint64_t)observer;
165
181
@end
166
182
@implementation NSDistributedNotificationCenterGDNCDummy
167
183
- (oneway void) postNotificationName: (NSString*)name
168
184
                              object: (NSString*)object
169
185
                            userInfo: (NSData*)info
170
186
                            selector: (NSString*)aSelector
171
 
                                  to: (NSUInteger)observer
 
187
                                  to: (uint64_t)observer
172
188
{
173
189
  return;
174
190
}
247
263
@interface      GDNCObserver : NSObject
248
264
{
249
265
@public
250
 
  NSUInteger            observer;
 
266
  uint64_t              observer;
251
267
  NSString              *notificationName;
252
268
  NSString              *notificationObject;
253
269
  NSString              *selector;
285
301
  NSMutableDictionary   *observersForObjects;
286
302
}
287
303
 
288
 
- (void) addObserver: (NSUInteger)anObserver
 
304
- (void) addObserver: (uint64_t)anObserver
289
305
            selector: (NSString*)aSelector
290
306
                name: (NSString*)notificationName
291
307
              object: (NSString*)anObject
297
313
 
298
314
- (id) connectionBecameInvalid: (NSNotification*)notification;
299
315
 
300
 
- (void) postNotificationName: (NSString*)notificationName
301
 
                       object: (NSString*)notificationObject
302
 
                     userInfo: (NSData*)d
303
 
           deliverImmediately: (BOOL)deliverImmediately
304
 
                          for: (id<GDNCClient>)client;
 
316
- (oneway void) postNotificationName: (NSString*)notificationName
 
317
                              object: (NSString*)notificationObject
 
318
                            userInfo: (NSData*)d
 
319
                  deliverImmediately: (BOOL)deliverImmediately
 
320
                                 for: (id<GDNCClient>)client;
305
321
 
306
322
- (void) removeObserver: (GDNCObserver*)observer;
307
323
 
308
324
- (void) removeObserversForClients: (NSMapTable*)clients;
309
325
 
310
 
- (void) removeObserver: (NSUInteger)anObserver
 
326
- (void) removeObserver: (uint64_t)anObserver
311
327
                   name: (NSString*)notificationName
312
328
                 object: (NSString*)notificationObject
313
329
                    for: (id<GDNCClient>)client;
506
522
  return self;
507
523
}
508
524
 
509
 
- (void) addObserver: (NSUInteger)anObserver
 
525
- (void) addObserver: (uint64_t)anObserver
510
526
            selector: (NSString*)aSelector
511
527
                name: (NSString*)notificationName
512
528
              object: (NSString*)anObject
519
535
  NSConnection  *connection;
520
536
 
521
537
  if (debugging)
522
 
    NSLog(@"Adding observer %lu for %@ %@",
 
538
    NSLog(@"Adding observer %llu for %@ %@",
523
539
      anObserver, notificationName, anObject);
524
540
 
525
541
  connection = [(NSDistantObject*)client connectionForProxy];
694
710
  RELEASE(info);
695
711
}
696
712
 
697
 
- (void) postNotificationName: (NSString*)notificationName
698
 
                       object: (NSString*)notificationObject
699
 
                     userInfo: (NSData*)d
700
 
           deliverImmediately: (BOOL)deliverImmediately
701
 
                          for: (id<GDNCClient>)client
 
713
- (oneway void) postNotificationName: (NSString*)notificationName
 
714
                              object: (NSString*)notificationObject
 
715
                            userInfo: (NSData*)d
 
716
                  deliverImmediately: (BOOL)deliverImmediately
 
717
                                 for: (id<GDNCClient>)client
702
718
{
703
719
  NSMutableArray        *observers = [NSMutableArray array];
704
720
  NSMutableArray        *byName;
802
818
                {
803
819
                  [obs->queue removeObjectAtIndex: 0];
804
820
  if (debugging)
805
 
    NSLog(@"Posting to observer %lu with %@", obs->observer, n);
 
821
    NSLog(@"Posting to observer %llu with %@", obs->observer, n);
806
822
                  [obs->client->client postNotificationName: n->name
807
823
                                                     object: n->object
808
824
                                                   userInfo: n->info
825
841
- (void) removeObserver: (GDNCObserver*)observer
826
842
{
827
843
  if (debugging)
828
 
    NSLog(@"Removing observer %lu for %@ %@",
 
844
    NSLog(@"Removing observer %llu for %@ %@",
829
845
      observer->observer, observer->notificationName,
830
846
      observer->notificationObject);
831
847
 
870
886
    }
871
887
}
872
888
 
873
 
- (void) removeObserver: (NSUInteger)anObserver
 
889
- (void) removeObserver: (uint64_t)anObserver
874
890
                   name: (NSString*)notificationName
875
891
                 object: (NSString*)notificationObject
876
892
                    for: (id<GDNCClient>)client
1060
1076
  CREATE_AUTORELEASE_POOL(pool);
1061
1077
 
1062
1078
#ifdef GS_PASS_ARGUMENTS
1063
 
  [NSProcessInfo initializeWithArguments: argv count: argc environment: env];
 
1079
  GSInitializeProcess(argc, argv, env);
1064
1080
#endif
1065
1081
  [NSObject enableDoubleReleaseCheck: YES];
1066
1082
  pInfo = [NSProcessInfo processInfo];
1121
1137
        }
1122
1138
      NS_HANDLER
1123
1139
        {
1124
 
          gdnc_log(LOG_CRIT);
 
1140
          gdnc_log(LOG_CRIT, [[localException description] UTF8String]);
1125
1141
          DESTROY(t);
1126
1142
        }
1127
1143
      NS_ENDHANDLER
1144
1160
#endif
1145
1161
        signal(sym, ihandler);
1146
1162
      }
1147
 
#ifndef __MINGW32__
 
1163
#ifndef __MINGW__
1148
1164
    signal(SIGPIPE, SIG_IGN);
1149
1165
    signal(SIGTTOU, SIG_IGN);
1150
1166
    signal(SIGTTIN, SIG_IGN);
1166
1182
     */
1167
1183
    [[NSFileHandle fileHandleWithStandardInput] closeFile];
1168
1184
    [[NSFileHandle fileHandleWithStandardOutput] closeFile];
1169
 
#ifndef __MINGW32__
 
1185
#ifndef __MINGW__
1170
1186
    if (debugging == NO)
1171
1187
      {
1172
1188
        [[NSFileHandle fileHandleWithStandardError] closeFile];