Creating Your Own Protocols

picture
1
point

Recently on the list, there was a question regarding creating your own protocols for QC. This is perhaps a 3+ part problem, and I've only addressed 1. Never the less, it's a good start I think :)

The Parts:

  • The Edit Conformance Information menu (I've addressed this one)
  • The Composition Repository patch (not addressed)
  • The New From Template Dialog (not addressed)

Making a new protocol is actually really simple. Using our "Skanky SDK" template makes it a snap.

Create a new project. Remove the CustomPatch.h, CustomPatch.m, CustomPatchUI.h, and CustomPatch.m files in the Patches directory (we don't need them for this exercise). The function we'll be working on is registerNodesWithManager:, located in CustomPatchPrincipal.m. Remove references and #imports of these files too.

Add these following lines before the @implementation line:

@interface QCCompositionRepository: NSObject
@end

This tells the compiler a bit about the Compo Repo that we're working with (actually, it doesn't say much at all, just that it's an extant class).

Next, clear out the registerNodesWithManager function. We're not adding patches, so we don't need any of the auto-generated stuff in there.

Next, the protocol dictionary construction!:

  1. NSMutableDictionary *infoDict =
  2. [[NSMutableDictionary alloc] init];
  3. NSMutableDictionary *optionalInputDict =
  4. [[NSMutableDictionary alloc] init];
  5. NSMutableDictionary *requiredInputDict =
  6. [[NSMutableDictionary alloc] init];
  7. NSMutableDictionary *optionalOutputDict =
  8. [[NSMutableDictionary alloc] init];
  9. NSMutableDictionary *requiredOutputDict =
  10. [[NSMutableDictionary alloc] init];
  11.  
  12. // add and remove your specific keys to the
  13. // appropriate structs -- Use the port's class
  14. // as the object, and a name that follows the pattern
  15. [optionalInputDict setObject:[QCStructurePort class]
  16. forKey:@"_protocolInput_OptionalInputStruct"];
  17. [requiredInputDict setObject:[QCStructurePort class]
  18. forKey:@"_protocolInput_RequiredInputStruct"];
  19. [optionalOutputDict setObject:[QCStructurePort class]
  20. forKey:@"_protocolInput_OptionalOutputStruct"];
  21. [requiredOutputDict setObject:[QCStructurePort class]
  22. forKey:@"_protocolInput_RequiredOutputStruct"];
  23.  
  24. // here we set some metadata about the protocol:
  25. // the display name (in the conformance dialog),
  26. // and whether or not we allow consumer patches.
  27. // (True in this example)
  28. [infoDict
  29. setObject:@"My Protocol's Display Name"
  30. forKey:@"name"];
  31. [infoDict
  32. setObject:[NSNumber numberWithBool:TRUE]
  33. forKey:@"allowConsumers"];
  34.  
  35. // We add the required and optional inputs
  36. // to the protocol dictionary...
  37. [infoDict setObject:optionalInputDict
  38. forKey:@"optionalInputKeys"];
  39. [infoDict setObject:requiredInputDict
  40. forKey:@"requiredInputKeys"];
  41. [infoDict setObject:optionalOutputDict
  42. forKey:@"optionalOutputKeys"];
  43. [infoDict setObject:requiredOutputDict
  44. forKey:@"requiredOutputKeys"];
  45.  
  46. // the we register it!
  47. [[QCCompositionRepository sharedCompositionRepository]
  48. registerProtocol:@"com.MyCompanyName.My-Protocol-Name"
  49. withDescription:infoDict];
  50.  
  51. // here you should release all the dictionaries.
  52. // I'm lazy though, so you'll have to write that
  53. // yourself.

Feel free to use this code however you want. If you do though, please drop me a line or comment on this post, so I know I didn't waste all this time for nothing :)