]> err.no Git - sope/blob - sope-gdl1/GDLAccess/EOFaultHandler.m
added missing inline pathes
[sope] / sope-gdl1 / GDLAccess / EOFaultHandler.m
1 /* 
2    EOAdaptorChannel.m
3
4    Copyright (C) 1996 Free Software Foundation, Inc.
5
6    Author: Ovidiu Predescu <ovidiu@bx.logicnet.ro>
7    Date: October 1996
8
9    This file is part of the GNUstep Database Library.
10
11    This library is free software; you can redistribute it and/or
12    modify it under the terms of the GNU Library General Public
13    License as published by the Free Software Foundation; either
14    version 2 of the License, or (at your option) any later version.
15
16    This library is distributed in the hope that it will be useful,
17    but WITHOUT ANY WARRANTY; without even the implied warranty of
18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19    Library General Public License for more details.
20
21    You should have received a copy of the GNU Library General Public
22    License along with this library; see the file COPYING.LIB.
23    If not, write to the Free Software Foundation,
24    59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 */
26 // $Id: EOFaultHandler.m 1 2004-08-20 10:38:46Z znek $
27
28 #include "EOFaultHandler.h"
29 #include "EOFault.h"
30 #include "common.h"
31
32 #if NeXT_RUNTIME
33 #  if !defined(METHOD_NULL)
34 #    define METHOD_NULL NULL
35 #  endif
36 #endif
37
38 @implementation EOFaultHandler
39
40 - (void)setTargetClass:(Class)_class extraData:(void *)_extraData {
41   self->targetClass = _class;
42   self->extraData   = _extraData;
43 }
44
45 - (Class)targetClass; {
46   return self->targetClass;
47 }
48 - (void *)extraData {
49   return self->extraData;
50 }
51
52 /* firing */
53
54 - (BOOL)shouldPerformInvocation:(NSInvocation *)_invocation {
55   return YES;
56 }
57
58 - (void)faultWillFire:(EOFault *)_fault {
59 }
60
61 - (void)completeInitializationOfObject:(id)_object {
62   [self doesNotRecognizeSelector:_cmd];
63 }
64
65 /* fault reflection */
66
67 - (Class)classForFault:(EOFault *)_fault {
68 #if GNU_RUNTIME
69   return (object_is_instance(_fault))
70     ? [self targetClass]
71     : (*(Class *)_fault);
72 #else
73 #  warning TODO: add complete implementation for Apple/NeXT runtime!
74   return [self targetClass];
75 #endif
76 }
77
78 - (BOOL)respondsToSelector:(SEL)_selector forFault:(EOFault *)_fault {
79   Class class;
80
81   /* first check whether fault itself responds to selector */
82 #if GNU_RUNTIME
83   if (class_get_instance_method(*(Class *)_fault, _selector) != METHOD_NULL)
84     return YES;
85 #else
86 #  warning TODO: add implementation for NeXT/Apple runtime!
87 #endif
88
89   /* then check whether the target class does */
90   class = [self targetClass];
91 #if GNU_RUNTIME
92   return (class_get_instance_method(class, _selector) != NULL) ? YES : NO;
93 #else
94 #  warning TODO: use NeXT/Apple runtime function
95   return [(NSObject *)class methodForSelector:_selector] ? YES : NO;
96 #endif
97 }
98
99 - (BOOL)conformsToProtocol:(Protocol *)_protocol forFault:(EOFault *)_fault {
100   Class class, sClass;
101
102 #if GNU_RUNTIME
103   struct objc_protocol_list* protos;
104   int i;
105   
106   class = object_is_instance(_fault) ? [self targetClass] : (Class)_fault;
107   for (protos = class->protocols; protos; protos = protos->next) {
108     for (i = 0; i < protos->count; i++) {
109       if ([protos->list[i] conformsTo:_protocol])
110         return YES;
111     }
112   }
113 #else
114 #  warning TODO: implement on NeXT/Apple runtime!
115   class = [self targetClass];
116 #endif
117
118   return ((sClass = [class superclass]))
119     ? [sClass conformsToProtocol:_protocol]
120     : NO;
121 }
122
123 - (BOOL)isKindOfClass:(Class)_class forFault:(EOFault *)_fault {
124   Class class;
125
126 #if GNU_RUNTIME
127   class = object_is_instance(_fault) ? [self targetClass] : (Class)_fault;
128   for (; class != Nil; class = class_get_super_class(class)) {
129     if (class == _class)
130       return YES;
131   }
132 #else
133 #  warning TODO: add implementation for NeXT/Apple runtime!
134   class = [self targetClass];
135 #endif
136   return NO;
137 }
138
139 - (BOOL)isMemberOfClass:(Class)_class forFault:(EOFault *)_fault {
140   Class class;
141 #if GNU_RUNTIME
142   class = object_is_instance(_fault) ? [self targetClass] : (Class)_fault;
143 #else
144 #  warning TODO: add implementation for NeXT/Apple runtime!
145   class = [self targetClass];
146 #endif
147   return class == _class ? YES : NO;
148 }
149
150 - (NSMethodSignature *)methodSignatureForSelector:(SEL)_selector
151   forFault:(EOFault *)_fault
152 {
153 #if NeXT_Foundation_LIBRARY
154   // probably incorrect
155   return [_fault methodSignatureForSelector:_selector];
156 #else
157   register const char *types = NULL;
158
159   if (_selector == NULL) // invalid selector
160     return nil;
161
162 #if GNU_RUNTIME && 0
163   // GNU runtime selectors may be typed, a lookup may not be necessary
164   types = aSelector->sel_types;
165 #endif
166
167   /* first check for EOFault's own methods */
168   
169   if (types == NULL) {
170     // lookup method for selector
171     struct objc_method *mth;
172     mth = class_get_instance_method(*(Class *)_fault, _selector);
173     if (mth) types = mth->method_types;
174   }
175   
176   /* then check in target class methods */
177   
178   if (types == NULL) {
179     // lookup method for selector
180     struct objc_method *mth;
181     mth = class_get_instance_method([self targetClass], _selector);
182     if (mth) types = mth->method_types;
183   }
184   
185 #if GNU_RUNTIME
186   // GNU runtime selectors may be typed, a lookup may not be necessary
187   if (types == NULL)
188     types = _selector->sel_types;
189 #endif
190   if (types == NULL)
191     return nil;
192   
193   return [NSMethodSignature signatureWithObjCTypes:types];
194 #endif
195 }
196
197 /* description */
198
199 - (NSString *)descriptionForObject:(id)_fault {
200   return [NSString stringWithFormat:@"<%@[0x%08X]: on=%@>",
201                      NSStringFromClass(*(Class *)_fault),
202                      _fault,
203                      NSStringFromClass([self targetClass])];
204 }
205
206 @end /* EOFaultHandler */