Oolite
Loading...
Searching...
No Matches
OOJSInterfaceDefinition Class Reference

#include <OOJSInterfaceDefinition.h>

Inheritance diagram for OOJSInterfaceDefinition:
Collaboration diagram for OOJSInterfaceDefinition:

Instance Methods

(NSString *) - title
(void) - setTitle:
(NSString *) - category
(void) - setCategory:
(NSString *) - summary
(void) - setSummary:
(jsval) - callback
(void) - setCallback:
(JSObject *) - callbackThis
(void) - setCallbackThis:
(void) - runCallback:
(NSComparisonResult) - interfaceCompare:
(NSString *) - title
(void) - setTitle:
(NSString *) - category
(void) - setCategory:
(NSString *) - summary
(void) - setSummary:
(JSValue) - callback
(void) - setCallback:
(JSValue) - callbackThis
(void) - setCallbackThis:
(void) - runCallback:
(NSComparisonResult) - interfaceCompare:
(id) - init [implementation]
(void) - deleteJSPointers [implementation]
(void) - dealloc [implementation]
Instance Methods inherited from OOWeakRefObject
(id) - weakSelf
(id) - weakRetain [implementation]
(void) - weakRefDied: [implementation]
Instance Methods inherited from <OOWeakReferenceSupport>
(id) - OO_RETURNS_RETAINED

Private Attributes

jsval _callback
JSObject * _callbackThis
OOJSScript * _owningScript
NSString * _title
NSString * _summary
NSString * _category
JSValue _callback
JSValue _callbackThis

Additional Inherited Members

Protected Attributes inherited from OOWeakRefObject
OOWeakReference * weakSelf

Detailed Description

Definition at line 29 of file OOJSInterfaceDefinition.h.

Method Documentation

◆ callback [1/2]

- (JSValue) callback

Definition at line 107 of file OOJSInterfaceDefinition.m.

108{
109 return JS_DupValue(OOJSAcquireContext(), _callback);
110}
OOINLINE JSContext * OOJSAcquireContext(void)

References _callback, callback, and OOJSAcquireContext().

Referenced by callback, runCallback:, and setCallback:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ callback [2/2]

- (JSValue) callback

References callback.

Here is the call graph for this function:

◆ callbackThis [1/2]

- (JSValue) callbackThis

Definition at line 121 of file OOJSInterfaceDefinition.m.

122{
123 return JS_DupValue(OOJSAcquireContext(), _callbackThis);
124}

References _callbackThis, callbackThis, and OOJSAcquireContext().

Referenced by callbackThis, runCallback:, and setCallbackThis:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ callbackThis [2/2]

- (JSValue) callbackThis

References callbackThis.

Here is the call graph for this function:

◆ category [1/2]

- (NSString *) category

Definition at line 85 of file OOJSInterfaceDefinition.m.

86{
87 return _category;
88}

References _category, and category.

Referenced by category, interfaceCompare:, and PlayerEntity::setGuiToInterfacesScreen:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ category [2/2]

- (NSString *) category

References category.

Here is the call graph for this function:

◆ dealloc

- (void) dealloc
implementation

Reimplemented from OOWeakRefObject.

Definition at line 63 of file OOJSInterfaceDefinition.m.

64{
65 [_owningScript release];
66
67 [self deleteJSPointers];
68
69 [super dealloc];
70}

References dealloc, OOWeakRefObject::dealloc, and deleteJSPointers.

Referenced by dealloc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ deleteJSPointers

- (void) deleteJSPointers
implementation

Definition at line 47 of file OOJSInterfaceDefinition.m.

48{
49
50 JSContext* context = OOJSAcquireContext();
51 _callback = JSVAL_VOID;
52 _callbackThis = NULL;
53 JS_RemoveValueRoot(context, &_callback);
54 JS_RemoveObjectRoot(context, &_callbackThis);
55
56 OOJSRelinquishContext(context);
57
58 [[NSNotificationCenter defaultCenter] removeObserver:self
59 name:kOOJavaScriptEngineWillResetNotification
61}
OOINLINE void OOJSRelinquishContext(JSContext *context)
OOJavaScriptEngine * sharedEngine()

References _callback, _callbackThis, deleteJSPointers, OOJSAcquireContext(), OOJSRelinquishContext(), and OOJavaScriptEngine::sharedEngine.

Referenced by dealloc, and deleteJSPointers.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init

- (id) init
implementation

Definition at line 31 of file OOJSInterfaceDefinition.m.

32{
33 self = [super init];
34 _callback = JSVAL_VOID;
35 _callbackThis = NULL;
36
38
39 [[NSNotificationCenter defaultCenter] addObserver:self
40 selector:@selector(deleteJSPointers)
41 name:kOOJavaScriptEngineWillResetNotification
43
44 return self;
45}
OOJSScript * currentlyRunningScript()
Definition OOJSScript.m:101

References _callback, _callbackThis, _owningScript, OOJSScript::currentlyRunningScript, init, OOJavaScriptEngine::sharedEngine, and OOJSScript::weakRetain.

Referenced by init.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ interfaceCompare: [1/2]

- (NSComparisonResult) interfaceCompare: (OOJSInterfaceDefinition*) other

Definition at line 171 of file OOJSInterfaceDefinition.m.

171 :(OOJSInterfaceDefinition*)other
172{
173 NSComparisonResult byCategory = [_category caseInsensitiveCompare:[other category]];
174 if (byCategory == NSOrderedSame) {
175 return [_title caseInsensitiveCompare:[other title]];
176 } else {
177 return byCategory;
178 }
179}

References category, and title.

Here is the call graph for this function:

◆ interfaceCompare: [2/2]

- (NSComparisonResult) interfaceCompare: (OOJSInterfaceDefinition *) other

◆ runCallback: [1/2]

- (void) runCallback: (NSString*) key

Definition at line 135 of file OOJSInterfaceDefinition.m.

135 :(NSString*)key
136{
137 OOJavaScriptEngine* engine = [OOJavaScriptEngine sharedEngine];
138 JSContext* context = OOJSAcquireContext();
139 JSValue rval = JS_UNDEFINED;
140
141 if (!JS_IsFunction(context, _callback)) {
142 // The callback was released by an engine reset.
143 OOJSRelinquishContext(context);
144 return;
145 }
146
147 JSValue cKey = OOJSValueFromNativeObject(context, key);
148
149 OOJSScript* owner = [_owningScript retain]; // local copy needed
150 [OOJSScript pushScript:owner];
151
152 // Hold our own references in case the callback replaces them.
153 JSValue callback = JS_DupValue(context, _callback);
154 JSValue callbackThis = JS_IsObject(_callbackThis) ? JS_DupValue(context, _callbackThis) : JS_UNDEFINED;
155 [engine callJSFunction:callback
156 forObject:callbackThis
157 argc:1
158 argv:&cKey
159 result:&rval];
160 JS_FreeValue(context, callback);
161 JS_FreeValue(context, callbackThis);
162
163 [OOJSScript popScript:owner];
164 [owner release];
165
166 JS_FreeValue(context, rval);
167 JS_FreeValue(context, cKey);
168 OOJSRelinquishContext(context);
169}
OOINLINE jsval OOJSValueFromNativeObject(JSContext *context, id object)
void pushScript:(OOJSScript *script)
Definition OOJSScript.m:480
void popScript:(OOJSScript *script)
Definition OOJSScript.m:493
BOOL callJSFunction:forObject:argc:argv:result:(jsval function,[forObject] JSObject *jsThis,[argc] uintN argc,[argv] jsval *argv,[result] jsval *outResult)

References _callback, _callbackThis, callback, callbackThis, OOJavaScriptEngine::callJSFunction:forObject:argc:argv:result:, OOJSAcquireContext(), OOJSRelinquishContext(), OOJSValueFromNativeObject(), OOJSScript::popScript:, OOJSScript::pushScript:, and OOJavaScriptEngine::sharedEngine.

Referenced by PlayerEntity::activateSelectedInterface.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ runCallback: [2/2]

- (void) runCallback: (NSString *) key

◆ setCallback: [1/2]

- (void) setCallback: (jsval) callback

Definition at line 112 of file OOJSInterfaceDefinition.m.

112 :(JSValueConst)callback
113{
114 JSContext* context = OOJSAcquireContext();
115 JSValue old = _callback;
116 _callback = JS_DupValue(context, callback);
117 JS_FreeValue(context, old);
118 OOJSRelinquishContext(context);
119}

References _callback, callback, OOJSAcquireContext(), and OOJSRelinquishContext().

Referenced by StationSetInterface(), and StationSetInterface().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setCallback: [2/2]

- (void) setCallback: (JSValueConst) callback

Definition at line 112 of file OOJSInterfaceDefinition.m.

112 :(JSValueConst)callback
113{
114 JSContext* context = OOJSAcquireContext();
115 JSValue old = _callback;
116 _callback = JS_DupValue(context, callback);
117 JS_FreeValue(context, old);
118 OOJSRelinquishContext(context);
119}

◆ setCallbackThis: [1/2]

- (void) setCallbackThis: (JSObject*) callbackthis

Definition at line 126 of file OOJSInterfaceDefinition.m.

126 :(JSValueConst)callbackThis
127{
128 JSContext* context = OOJSAcquireContext();
129 JSValue old = _callbackThis;
130 _callbackThis = JS_DupValue(context, callbackThis);
131 JS_FreeValue(context, old);
132 OOJSRelinquishContext(context);
133}

References _callbackThis, callbackThis, OOJSAcquireContext(), and OOJSRelinquishContext().

Referenced by StationSetInterface(), and StationSetInterface().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setCallbackThis: [2/2]

- (void) setCallbackThis: (JSValueConst) callbackthis

Definition at line 126 of file OOJSInterfaceDefinition.m.

126 :(JSValueConst)callbackThis
127{
128 JSContext* context = OOJSAcquireContext();
129 JSValue old = _callbackThis;
130 _callbackThis = JS_DupValue(context, callbackThis);
131 JS_FreeValue(context, old);
132 OOJSRelinquishContext(context);
133}

◆ setCategory: [1/2]

- (void) setCategory: (NSString*) category

Definition at line 90 of file OOJSInterfaceDefinition.m.

90 :(NSString*)category
91{
92 [_category autorelease];
93 _category = [category retain];
94}

References _category.

Referenced by StationSetInterface(), and StationSetInterface().

Here is the caller graph for this function:

◆ setCategory: [2/2]

- (void) setCategory: (NSString *) category

◆ setSummary: [1/2]

- (void) setSummary: (NSString*) summary

Definition at line 101 of file OOJSInterfaceDefinition.m.

101 :(NSString*)summary
102{
103 [_summary autorelease];
104 _summary = [summary retain];
105}

References _summary.

Referenced by StationSetInterface(), and StationSetInterface().

Here is the caller graph for this function:

◆ setSummary: [2/2]

- (void) setSummary: (NSString *) summary

◆ setTitle: [1/2]

- (void) setTitle: (NSString*) title

Definition at line 79 of file OOJSInterfaceDefinition.m.

79 :(NSString*)title
80{
81 [_title autorelease];
82 _title = [title retain];
83}

References _title.

Referenced by StationSetInterface(), and StationSetInterface().

Here is the caller graph for this function:

◆ setTitle: [2/2]

- (void) setTitle: (NSString *) title

◆ summary [1/2]

- (NSString *) summary

Definition at line 96 of file OOJSInterfaceDefinition.m.

97{
98 return _summary;
99}

References _summary, and summary.

Referenced by PlayerEntity::showInformationForSelectedInterface, and summary.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ summary [2/2]

- (NSString *) summary

References summary.

Here is the call graph for this function:

◆ title [1/2]

- (NSString *) title

Definition at line 74 of file OOJSInterfaceDefinition.m.

75{
76 return _title;
77}

References _title, and title.

Referenced by interfaceCompare:, PlayerEntity::setGuiToInterfacesScreen:, and title.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ title [2/2]

- (NSString *) title

References title.

Here is the call graph for this function:

Member Data Documentation

◆ _callback [1/2]

- (jsval) _callback
private

Definition at line 31 of file OOJSInterfaceDefinition.h.

Referenced by callback, deleteJSPointers, init, runCallback:, and setCallback:.

◆ _callback [2/2]

- (JSValue) _callback
private

Definition at line 34 of file OOJSInterfaceDefinition.h.

◆ _callbackThis [1/2]

- (JSObject*) _callbackThis
private

Definition at line 32 of file OOJSInterfaceDefinition.h.

Referenced by callbackThis, deleteJSPointers, init, runCallback:, and setCallbackThis:.

◆ _callbackThis [2/2]

- (JSValue) _callbackThis
private

Definition at line 35 of file OOJSInterfaceDefinition.h.

◆ _category

- (NSString *) _category
private

Definition at line 37 of file OOJSInterfaceDefinition.h.

Referenced by category, and setCategory:.

◆ _owningScript

- (OOJSScript *) _owningScript
private

Definition at line 33 of file OOJSInterfaceDefinition.h.

Referenced by init.

◆ _summary

- (NSString *) _summary
private

Definition at line 36 of file OOJSInterfaceDefinition.h.

Referenced by setSummary:, and summary.

◆ _title

- (NSString *) _title
private

Definition at line 35 of file OOJSInterfaceDefinition.h.

Referenced by setTitle:, and title.


The documentation for this class was generated from the following files: