CGEchoNode.m 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /******************************************************************
  2. *
  3. * uEcho for ObjC
  4. *
  5. * Copyright (C) Satoshi Konno 2015
  6. *
  7. * This is licensed under BSD-style license, see file COPYING.
  8. *
  9. ******************************************************************/
  10. #import "CGEchoNode.h"
  11. #import "CGEchoObject.h"
  12. #include <uecho/node.h>
  13. @implementation CGEchoNode {
  14. }
  15. @synthesize cObject;
  16. - (id)initWithCObject:(uEchoNode*)cobj
  17. {
  18. if ((self = [super init]) == nil)
  19. return nil;
  20. cObject = cobj;
  21. return self;
  22. }
  23. - (void)dealloc
  24. {
  25. }
  26. - (NSString*)address
  27. {
  28. if (!cObject)
  29. return nil;
  30. const char* addr = uecho_node_getaddress(cObject);
  31. if (!addr)
  32. return nil;
  33. return [NSString stringWithUTF8String:addr];
  34. }
  35. - (NSArray*)objects;
  36. {
  37. if (!cObject)
  38. return [NSArray array];
  39. NSMutableArray* objs = [NSMutableArray array];
  40. for (uEchoNode* cObj = uecho_node_getobjects(cObject); cObj; cObj = uecho_object_next(cObj)) {
  41. CGEchoObject* obj = [[CGEchoObject alloc] initWithCObject:cObj];
  42. [objs addObject:obj];
  43. }
  44. return objs;
  45. }
  46. @end