Author: rmottola
Date: Wed Jun  1 13:01:11 2016
New Revision: 39828

URL: http://svn.gna.org/viewcvs/gnustep?rev=39828&view=rev
Log:
Use DO and connections to communicate to thread

Removed:
    apps/gworkspace/trunk/Inspector/ContentViewers/ImageViewer/resizer/
Modified:
    apps/gworkspace/trunk/ChangeLog
    apps/gworkspace/trunk/Inspector/ContentViewers/ImageViewer/ImageViewer.h
    apps/gworkspace/trunk/Inspector/ContentViewers/ImageViewer/ImageViewer.m
    apps/gworkspace/trunk/Inspector/ContentViewers/ImageViewer/Resizer.h
    apps/gworkspace/trunk/Inspector/ContentViewers/ImageViewer/Resizer.m

Modified: apps/gworkspace/trunk/ChangeLog
URL: 
http://svn.gna.org/viewcvs/gnustep/apps/gworkspace/trunk/ChangeLog?rev=39828&r1=39827&r2=39828&view=diff
==============================================================================
--- apps/gworkspace/trunk/ChangeLog     (original)
+++ apps/gworkspace/trunk/ChangeLog     Wed Jun  1 13:01:11 2016
@@ -1,3 +1,11 @@
+2016-06-01 Riccardo Mottola <r...@gnu.org>
+
+       * Inspector/ContentViewers/ImageViewer/ImageViewer.h
+       * Inspector/ContentViewers/ImageViewer/ImageViewer.m
+       * Inspector/ContentViewers/ImageViewer/Resizer.h
+       * Inspector/ContentViewers/ImageViewer/Resizer.m
+       Use DO and connections to communicate to thread.
+
 2016-06-01 Riccardo Mottola <r...@gnu.org>
 
        * Inspector/ContentViewers/ImageViewer/ImageViewer.h

Modified: 
apps/gworkspace/trunk/Inspector/ContentViewers/ImageViewer/ImageViewer.h
URL: 
http://svn.gna.org/viewcvs/gnustep/apps/gworkspace/trunk/Inspector/ContentViewers/ImageViewer/ImageViewer.h?rev=39828&r1=39827&r2=39828&view=diff
==============================================================================
--- apps/gworkspace/trunk/Inspector/ContentViewers/ImageViewer/ImageViewer.h    
(original)
+++ apps/gworkspace/trunk/Inspector/ContentViewers/ImageViewer/ImageViewer.h    
Wed Jun  1 13:01:11 2016
@@ -35,7 +35,7 @@
 @class NSButton;
 @class NSWorkspace;
 @class ProgressView;
-
+@class ImageResizer;
 @protocol ContentInspectorProtocol
 
 - (void)contentsReadyAt:(NSString *)path;
@@ -71,7 +71,7 @@
   NSConnection *conn;  
   NSConnection *resizerConn;
   BOOL waitingResizer;
-  id resizer;
+  ImageResizer *resizer;
   
   id <ContentInspectorProtocol>inspector;
   NSFileManager *fm;
@@ -84,7 +84,7 @@
 - (void)setResizer:(id)anObject;
 
 - (BOOL)connection:(NSConnection *)ancestor 
-                                                               
shouldMakeNewConnection:(NSConnection *)newConn;
+shouldMakeNewConnection:(NSConnection *)newConn;
 
 - (void)connectionDidDie:(NSNotification *)notification;
 

Modified: 
apps/gworkspace/trunk/Inspector/ContentViewers/ImageViewer/ImageViewer.m
URL: 
http://svn.gna.org/viewcvs/gnustep/apps/gworkspace/trunk/Inspector/ContentViewers/ImageViewer/ImageViewer.m?rev=39828&r1=39827&r2=39828&view=diff
==============================================================================
--- apps/gworkspace/trunk/Inspector/ContentViewers/ImageViewer/ImageViewer.m    
(original)
+++ apps/gworkspace/trunk/Inspector/ContentViewers/ImageViewer/ImageViewer.m    
Wed Jun  1 13:01:11 2016
@@ -1,8 +1,9 @@
 /* ImageViewer.m
  *  
- * Copyright (C) 2004-2013 Free Software Foundation, Inc.
+ * Copyright (C) 2004-2016 Free Software Foundation, Inc.
  *
  * Author: Enrico Sersale <enr...@imago.ro>
+ *         Riccardo Mottola <r...@gnu.org>
  * Date: January 2004
  *
  * This file is part of the GNUstep Inspector application
@@ -159,42 +160,41 @@
   DESTROY (editPath);
   [editButt setEnabled: NO];           
   
-  if (imagePath) {
-    ASSIGN (nextPath, path);
-    return;
-  }
+  if (imagePath)
+    {
+      ASSIGN (nextPath, path);
+      return;
+    }
   
   ASSIGN (imagePath, path);
 
-  if (conn == nil) {
-    NSString *cname = [NSString stringWithFormat: @"search_%lu", (unsigned 
long)self];
-
-    conn = [[NSConnection alloc] initWithReceivePort: (NSPort *)[NSPort port] 
-                                                                               
                                                                              
sendPort: nil];
-    [conn setRootObject: self];
-    [conn registerName: cname];
-    [conn setDelegate: self];
-
-    [nc addObserver: self
-           selector: @selector(connectionDidDie:)
-               name: NSConnectionDidDieNotification
-             object: conn];    
-  }
-  
-  if ((resizer == nil) && (waitingResizer == NO)) {
-    NSString *cname = [NSString stringWithFormat: @"search_%lu", (unsigned 
long)self];
-
-    waitingResizer = YES;
-
-    [NSTimer scheduledTimerWithTimeInterval: 5.0 
-                                                                        
target: self
-                                   selector: @selector(checkResizer:) 
-                                                                               
                                                   userInfo: nil 
-                                    repeats: NO];
-    ImageResizer *resizer = [[ImageResizer alloc] initWithConnectionName: 
cname];
-  } else {
+  if (conn == nil)
+    {
+      NSPort *p1;
+      NSPort *p2;  
+      NSString *cname;
+
+      p1 = [NSPort port];
+      p2 = [NSPort port];
+      cname = [NSString stringWithFormat: @"search_%lu", (unsigned long)self];
+
+      conn = [[NSConnection alloc] initWithReceivePort: p1 
+                                              sendPort: p2];
+      [conn setRootObject:self];
+
+      [NSThread detachNewThreadSelector: @selector(connectWithPorts:)
+                               toTarget: [ImageResizer class]
+                             withObject: [NSArray arrayWithObjects: p2, p1, 
nil]];
+
+      [nc addObserver: self
+             selector: @selector(connectionDidDie:)
+                 name: NSConnectionDidDieNotification
+               object: conn];    
+    }
+  
+  if (!(resizer == nil)) {
     NSSize imsize = [imview bounds].size;
-    
+
     imsize.width -= 4;
     imsize.height -= 4;
     [self addSubview: progView]; 
@@ -224,6 +224,11 @@
                     nil, 
                     nil);
   }
+}
+
+- (void)setServer:(id)anObject
+{
+  [self setResizer:anObject];
 }
 
 - (void)setResizer:(id)anObject
@@ -244,18 +249,18 @@
 }
 
 - (BOOL)connection:(NSConnection *)ancestor 
-                                                               
shouldMakeNewConnection:(NSConnection *)newConn
-{
-       if (ancestor == conn) {
+shouldMakeNewConnection:(NSConnection *)newConn
+{
+  if (ancestor == conn) {
     ASSIGN (resizerConn, newConn);
-       [resizerConn setDelegate: self];
-    
-       [nc addObserver: self 
-                                        selector: @selector(connectionDidDie:)
-                                        name: NSConnectionDidDieNotification 
+    [resizerConn setDelegate: self];
+    
+    [nc addObserver: self 
+           selector: @selector(connectionDidDie:)
+               name: NSConnectionDidDieNotification 
              object: resizerConn];
-       }
-               
+  }
+  
   return YES;
 }
 
@@ -293,11 +298,13 @@
 
 - (void)imageReady:(NSData *)data
 {
-  NSDictionary *imginfo = [NSUnarchiver unarchiveObjectWithData: data];
-  NSData *imgdata = [imginfo objectForKey: @"imgdata"];
+  NSDictionary *imginfo;
+  NSData *imgdata;
   BOOL imgok = YES;
   NSString *lastPath;
-  
+
+  imginfo = [NSUnarchiver unarchiveObjectWithData: data];
+  imgdata = [imginfo objectForKey: @"imgdata"];
   if ([self superview]) {      
     [inspector contentsReadyAt: imagePath];
   }

Modified: apps/gworkspace/trunk/Inspector/ContentViewers/ImageViewer/Resizer.h
URL: 
http://svn.gna.org/viewcvs/gnustep/apps/gworkspace/trunk/Inspector/ContentViewers/ImageViewer/Resizer.h?rev=39828&r1=39827&r2=39828&view=diff
==============================================================================
--- apps/gworkspace/trunk/Inspector/ContentViewers/ImageViewer/Resizer.h        
(original)
+++ apps/gworkspace/trunk/Inspector/ContentViewers/ImageViewer/Resizer.h        
Wed Jun  1 13:01:11 2016
@@ -23,10 +23,13 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
  */
 
+
+NSConnection *serverConnection;
+
 @interface ImageResizer : NSObject
 {
   id viewer;
-  NSNotificationCenter *nc; 
+  NSNotificationCenter *nc;
 }
 
 - (id)initWithConnectionName:(NSString *)cname;

Modified: apps/gworkspace/trunk/Inspector/ContentViewers/ImageViewer/Resizer.m
URL: 
http://svn.gna.org/viewcvs/gnustep/apps/gworkspace/trunk/Inspector/ContentViewers/ImageViewer/Resizer.m?rev=39828&r1=39827&r2=39828&view=diff
==============================================================================
--- apps/gworkspace/trunk/Inspector/ContentViewers/ImageViewer/Resizer.m        
(original)
+++ apps/gworkspace/trunk/Inspector/ContentViewers/ImageViewer/Resizer.m        
Wed Jun  1 13:01:11 2016
@@ -3,6 +3,7 @@
  * Copyright (C) 2005-2016 Free Software Foundation, Inc.
  *
  * Author: Enrico Sersale <enr...@imago.ro>
+ *         Riccardo Mottola <r...@gnu.org>
  * Date: January 2005
  *
  * This file is part of the GNUstep Inspector application
@@ -46,44 +47,34 @@
 
 @implementation ImageResizer
 
++ (void)connectWithPorts:(NSArray *)portArray
+{
+  NSAutoreleasePool *pool;
+  ImageResizer *serverObject;
+
+  pool = [[NSAutoreleasePool alloc] init];
+
+  serverConnection = [NSConnection connectionWithReceivePort: [portArray 
objectAtIndex:0]
+                                                    sendPort: [portArray 
objectAtIndex:1]];
+
+  serverObject = [[self alloc] init];
+  if (serverObject)
+    {
+      NSLog(@"setting server");
+      [[serverConnection rootProxy] setServer:serverObject];
+      [serverObject release];
+      [[NSRunLoop currentRunLoop] run];
+    }
+  [pool release];
+  [NSThread exit];
+}
+
+
 - (void)dealloc
 {
   [nc removeObserver: self];
        DESTROY (viewer);
   [super dealloc];
-}
-
-- (id)initWithConnectionName:(NSString *)cname
-{
-  self = [super init];
-  
-  if (self) {
-    NSConnection *conn;
-    id anObject;
-
-    nc = [NSNotificationCenter defaultCenter];
-
-    conn = [NSConnection connectionWithRegisteredName: cname host: nil];
-    
-    if (conn == nil) {
-      NSLog(@"failed to contact the Image Viewer - bye.");
-           exit(1);           
-    } 
-
-    [nc addObserver: self
-           selector: @selector(connectionDidDie:)
-               name: NSConnectionDidDieNotification
-             object: conn];    
-    
-    anObject = [conn rootProxy];
-    [anObject setProtocolForProxy: @protocol(ImageViewerProtocol)];
-    viewer = (id <ImageViewerProtocol>)anObject;
-    RETAIN (viewer);
-
-    [viewer setResizer: self];
-  }
-  
-  return self;
 }
 
 - (void)connectionDidDie:(NSNotification *)notification
@@ -214,9 +205,7 @@
     
     RELEASE (srcImage);
   }
-  
-  [viewer imageReady: [NSArchiver archivedDataWithRootObject: info]];
-  
+  [[serverConnection rootProxy] imageReady: [NSArchiver 
archivedDataWithRootObject: info]];
   RELEASE (arp);
 }
 


_______________________________________________
Gnustep-cvs mailing list
Gnustep-cvs@gna.org
https://mail.gna.org/listinfo/gnustep-cvs

Reply via email to