Code:
-(void)encodeELF:(NSData *)data
{
//initialize variable and allocate memory
NSDictionary loadElfReturn;;
NSString* filespace=[[NSString alloc]initWithData:data encoding:NSASCIIStringEncoding];
virtual_machine_32 *vm = [[virtual_machine_32 alloc]init];
NSInvocationOperation *parseOp=[[NSInvocationOperation alloc]initWithTarget:self selector:@selector(printToScreen:) object:@" Parsing Executable...\n"];
[operationQueue addOperation:parseOp];
[parseOp release];
NSInvocationOperation *loadelfOp=[[NSInvocationOperation alloc]initWithTarget:vm selector:@selector(loadelf:) object:filespace];
[operationQueue addOperation:loadelfOp];
[COLOR="Red"]loadElfReturn=[loadelfOp result];[/COLOR]
[loadelfOp release];
Parameters *send=[[Parameters alloc]init];
send.memory=[loadElfReturn objectForKey:@"Memory"];
send.symbol_table=[loadElfReturn objectForKey:@"SymbolTable"];
send.entryPoint=[loadElfReturn objectForKey:@"Entry"];
arch=[[loadElfReturn objectForKey:@"Arch"]shortValue];
NSInvocationOperation *execPrintOp=[[NSInvocationOperation alloc]initWithTarget:self selector:@selector(printToScreen:) object:@" Executing...\n"];
[operationQueue addOperation:execPrintOp];
[execPrintOp release];
NSInvocationOperation *executeOp=[[NSInvocationOperation alloc]initWithTarget:vm selector:@selector(vm32:) object:send];
[operationQueue addOperation:executeOp];
[executeOp release];
//free memory
[vm release];
[filespace release];
NSInvocationOperation *uploadRequestOp=[[NSInvocationOperation alloc]initWithTarget:self selector:@selector(uploadDataRequest) object:nil];
[operationQueue addOperation:uploadRequestOp];
[uploadRequestOp release];
}
Looking at this it's my understanding that all of these things should be done sequentially. Meaning I should get "Parsing Executable..." on the screen, THEN I should run loadelf: and get the response from that THEN print "Executing..." to the screen, then once that is finished run vm32:, and finall run the requestUpload: function. But that isn't what is happening. It appears to be requesting the upload prior to finishing the vm32: function because what is getting uploaded isn't the result of vm32:
The red-hilited code is almost certainly wrong. First, you're not taking the possibility of nil into account. Second, you're not actually checking to see if the operation has completed (see the NSOperation class docs). The operation was just queued. Trust me, it's not going to complete that quickly. If you wanted synchronous (i.e. strict sequential) execution, then you need to design the code it does that. What you've coded does not do that.
The whole point of queueing an operation is to perform it asynchronously. Your description of your understanding is almost the exact opposite of what the code appears to represent. In fact, I can't see why you'd be doing all those queued operations when what it seems you want is strict sequentiality.
Your description is for a sequence of actions, to be performed exactly in sequence. I see NO possibility for one action to be performed without its predecessor being completed. If you believe there is, then either you're mistaken or you haven't adequately explained what problem you're trying to solve by all this. It looks to me like every action requires it's predecessor's completion (load file, parse symbols, extract symbols, blah, blah, etc.).
I can see why some actions should completed before the display is updated, and I can see intermediate notifications that are displayed, but I see no reason why the actions shouldn't be done in sequence in a single async operation. There is no reason to block the main thread waiting for results to display, when those results can be delivered asynchronously. Blocking the main thread is wrong, and attempts to do so are severely misguided.
If the actions are time-consuming, then simple logic suggests that the time-consuming part be done in the background, and the display only updated after the time-consuming part has completed. If intermediate notifications are needed, they can be delivered when intermediate waypoints are reached.
Sadly, that's not at all what you've coded here. Instead, you've got a bunch of asynch operations (which shouldn't be done asynch'ly relative to one another), followed by some text update that should be done by callbacks, or notifications, which requires the completed results from the async operations.
I think you need to completely reread the Threading Programming Guide that's the Companion Guide for NSInvocationOperation.
http://developer.apple.com/library/...ationOperation_Class/Reference/Reference.html
Then you need to completely redesign the code so that the things that need to occur in strict sequence actually occur in strict sequence, and you're not waiting for those to complete on the main thread. Then after completion, you can update the text display using a notification or callback. The current mish-mash of async and sync is never going to work.
You should describe exactly what you're trying to accomplish, instead of describing how you're trying to accomplish it. I can tell you the "how" right now is almost completely wrong. What I'm unclear on is the "what", in order to suggest a more suitable "how".
Finally, it's impossible to fully understand what's happening in the code without seeing the code for the methods that your operations invoke.