Permalink
Browse files

add iphone API generator files

  • Loading branch information...
1 parent 5ef5bb7 commit 6474748f556ddd72e63a2fbeee8d27f675f19892 @dmitrys dmitrys committed Dec 30, 2012
Showing with 989 additions and 1 deletion.
  1. +13 −0 platform/shared/api_generator/common/iphone/CJSConverter.h
  2. +16 −0 platform/shared/api_generator/common/iphone/CJSConverter.m
  3. +30 −0 platform/shared/api_generator/common/iphone/CMethodResult.h
  4. +79 −0 platform/shared/api_generator/common/iphone/CMethodResult.m
  5. +13 −0 platform/shared/api_generator/common/iphone/CRubyConverter.h
  6. +88 −0 platform/shared/api_generator/common/iphone/CRubyConverter.m
  7. +8 −0 platform/shared/api_generator/common/iphone/IMethodResult.h
  8. +18 −0 platform/shared/api_generator/common/iphone/RubyCallbackHelper.h
  9. +73 −0 platform/shared/api_generator/common/iphone/RubyCallbackHelper.mm
  10. +1 −0 platform/shared/api_generator/common/iphone/readme.txt
  11. +1 −1 platform/shared/api_generator/sample/barcode1_js_api.cpp
  12. +34 −0 platform/shared/api_generator/sample/iphone/api/IBarcode1.h
  13. +2 −0 platform/shared/api_generator/sample/iphone/api/readme.txt
  14. +18 −0 platform/shared/api_generator/sample/iphone/impl/Barcode1.h
  15. +63 −0 platform/shared/api_generator/sample/iphone/impl/Barcode1.m
  16. +21 −0 platform/shared/api_generator/sample/iphone/impl/Barcode1Base.h
  17. +37 −0 platform/shared/api_generator/sample/iphone/impl/Barcode1Base.m
  18. +19 −0 platform/shared/api_generator/sample/iphone/impl/Barcode1BaseFactory.h
  19. +49 −0 platform/shared/api_generator/sample/iphone/impl/Barcode1BaseFactory.m
  20. +10 −0 platform/shared/api_generator/sample/iphone/impl/Barcode1Factory.h
  21. +18 −0 platform/shared/api_generator/sample/iphone/impl/Barcode1Factory.m
  22. +17 −0 platform/shared/api_generator/sample/iphone/impl/Barcode1Singletone.m
  23. +4 −0 platform/shared/api_generator/sample/iphone/impl/readme.txt
  24. +9 −0 platform/shared/api_generator/sample/iphone/javascript_wrapper/barcode1_js_wrapper.mm
  25. +2 −0 platform/shared/api_generator/sample/iphone/javascript_wrapper/readme.txt
  26. +262 −0 platform/shared/api_generator/sample/iphone/ruby_wrapper/barcode1_ruby_wrap.m
  27. +2 −0 platform/shared/api_generator/sample/iphone/ruby_wrapper/readme.txt
  28. +18 −0 platform/shared/api_generator/sample/readme.txt
  29. +46 −0 platform/shared/api_generator/sample/test/ruby/BarcodeTest/controller.rb
  30. +3 −0 platform/shared/api_generator/sample/test/ruby/BarcodeTest/index.erb
  31. +15 −0 platform/shared/api_generator/sample/test/ruby/BarcodeTest/layout.erb
@@ -0,0 +1,13 @@
+
+#import <Foundation/Foundation.h>
+#import "IMethodResult.h"
+#import "ruby/ext/rho/rhoruby.h"
+
+@interface CJSConverter : NSObject {
+}
+
++ (NSString*) convertToJS:(NSObject*)objectiveC_value;
+
++ (NSObject*) convertFromJS:(NSString*)js_value;
+
+@end
@@ -0,0 +1,16 @@
+
+#import "CJSConverter.h"
+
+@implementation CJSConverter
+
++ (NSString*) convertToJS:(NSObject*)objectiveC_value {
+ //TODO:
+ return nil;
+}
+
++ (NSObject*) convertFromJS:(NSString*)js_value {
+ //TODO:
+ return nil;
+}
+
+@end
@@ -0,0 +1,30 @@
+
+#import <Foundation/Foundation.h>
+#import "IMethodResult.h"
+#import "ruby/ext/rho/rhoruby.h"
+
+@interface CMethodResult : NSObject<IMethodResult> {
+ NSObject* mValue;
+ NSString* mRubyCallbackURL;
+ NSString* mJSCallbackUID;
+ NSString* mCallbackParam;
+}
+
+-(id) init;
+
+- (void) setResult:(NSObject*)value;
+
+-(NSObject*) getResult;
+
+-(VALUE) toRuby;
+-(NSString*) toJSON;
+
+-(void) setRubyCallback:(NSString*)url;
+-(void) setJSCallback:(NSString*)uid;
+-(void) setCallbackParam:(NSString*)param;
+
+-(void) callCallback;
+
+-(void) dealloc;
+
+@end
@@ -0,0 +1,79 @@
+
+#import "CMethodResult.h"
+
+#import "CRubyConverter.h"
+#import "CJSConverter.h"
+#import "RubyCallbackHelper.h"
+
+@implementation CMethodResult
+
+-(id) init {
+ self = [super init];
+ mValue = nil;
+ mRubyCallbackURL = nil;
+ mJSCallbackUID = nil;
+ mCallbackParam = nil;
+ return self;
+}
+
+- (void) setResult:(NSObject*)value {
+ mValue = [value retain];
+ [self callCallback];
+}
+
+-(NSObject*) getResult {
+ return mValue;
+}
+
+
+-(VALUE) toRuby {
+ return [CRubyConverter convertToRuby:mValue];
+}
+
+-(NSString*) toJSON {
+ return [CJSConverter convertToJS:mValue];
+}
+
+
+-(void) setRubyCallback:(NSString*)url {
+ mRubyCallbackURL = [url retain];
+}
+
+-(void) setJSCallback:(NSString*)uid {
+ mJSCallbackUID = [uid retain];
+}
+
+-(void) setCallbackParam:(NSString*)param {
+ mCallbackParam = [param retain];
+}
+
+-(void) callRubyCallback:(NSString*)url {
+ RubyCallbackHelper_callCallback(mRubyCallbackURL, self, mCallbackParam);
+}
+
+-(void) callJSCallback:(NSString*)uid {
+ //TODO:
+}
+
+-(void) callCallback {
+ if (mRubyCallbackURL != nil) {
+ [self callRubyCallback:mRubyCallbackURL];
+ }
+ else if (mJSCallbackUID != nil) {
+ [self callJSCallback:mJSCallbackUID];
+ }
+}
+
+
+
+
+-(void) dealloc {
+ [mRubyCallbackURL release];
+ [mJSCallbackUID release];
+ [mCallbackParam release];
+ [mValue release];
+ [super dealloc];
+}
+
+
+@end
@@ -0,0 +1,13 @@
+
+#import <Foundation/Foundation.h>
+#import "IMethodResult.h"
+#import "ruby/ext/rho/rhoruby.h"
+
+@interface CRubyConverter : NSObject {
+}
+
++ (VALUE) convertToRuby:(NSObject*)objectiveC_value;
+
++ (NSObject*) convertFromRuby:(VALUE)ruby_value;
+
+@end
@@ -0,0 +1,88 @@
+
+#import "CRubyConverter.h"
+#import "ruby/ext/rho/rhoruby.h"
+#import "ruby.h"
+
+@implementation CRubyConverter
+
++ (VALUE) convertToRuby:(NSObject*)objectiveC_value {
+ VALUE v = rho_ruby_get_NIL();
+
+ if ([objectiveC_value isKindOfClass:[NSString class]]) {
+ // string
+ NSString* objString = (NSString*)objectiveC_value;
+ v = rho_ruby_create_string([objString UTF8String]);
+ }
+ else if ([objectiveC_value isKindOfClass:[NSArray class]]) {
+ // array
+ NSArray* objArray = (NSArray*)objectiveC_value;
+ int count = [objArray count];
+ int i;
+ v = rho_ruby_create_array();
+ for (i = 0; i < count; i++) {
+ NSObject* obj = [objArray objectAtIndex:i];
+ VALUE objValue = [CRubyConverter convertToRuby:obj];
+ rho_ruby_add_to_array(v, objValue);
+ }
+ }
+ else if ([objectiveC_value isKindOfClass:[NSDictionary class]]) {
+ // dictionary
+ NSDictionary* objDictionary = (NSDictionary*)objectiveC_value;
+ v = rho_ruby_createHash();
+ NSEnumerator* enumerator = [objDictionary keyEnumerator];
+ NSObject* obj = nil;
+ while ((obj = [enumerator nextObject]) != nil) {
+ NSObject* objKey = obj;
+ NSObject* objValue = [objDictionary objectForKey:objKey];
+ VALUE vKey = [CRubyConverter convertToRuby:objKey];
+ VALUE vItem = [CRubyConverter convertToRuby:objValue];
+ rho_ruby_add_to_hash(v, vKey, vItem);
+ }
+ }
+
+ return v;
+}
+
++ (NSObject*) convertFromRuby:(VALUE)ruby_value {
+ int i, size;
+ switch(rb_type(ruby_value)) {
+ case T_ARRAY:
+ {
+ size = RARRAY_LEN(ruby_value);
+ NSMutableArray* ar = [NSMutableArray arrayWithCapacity:size];
+ for (i = 0; i < size; ++i) {
+ VALUE item = rb_ary_entry(ruby_value, i);
+ [ar addObject:[CRubyConverter convertFromRuby:item]];
+ }
+ return ar;
+ }
+ break;
+ case T_HASH:
+ {
+ VALUE keys = rb_funcall(ruby_value, rb_intern("keys"), 0, NULL);
+ size = RARRAY_LEN(keys);
+ NSMutableDictionary* dic = [NSMutableDictionary dictionaryWithCapacity:size];
+ for (i = 0; i < size; ++i) {
+ VALUE key = rb_ary_entry(keys, i);
+ VALUE value = rb_hash_aref(ruby_value, key);
+ [dic setObject:[CRubyConverter convertFromRuby:value] forKey:[CRubyConverter convertFromRuby:key]];
+ }
+ return dic;
+ }
+ break;
+ default:
+ {
+ VALUE value = ruby_value;
+ if (rho_ruby_is_NIL(value)) {
+ return [NSNull null];
+ }
+ if (rb_type(ruby_value) != T_STRING)
+ value = rb_funcall(value, rb_intern("to_s"), 0, NULL);
+ return [NSString stringWithUTF8String:RSTRING_PTR(value)];
+ }
+ }
+ return nil;
+}
+
+
+@end
@@ -0,0 +1,8 @@
+
+#import <Foundation/Foundation.h>
+
+@protocol IMethodResult <NSObject>
+
+- (void) setResult:(NSObject*)value;
+
+@end
@@ -0,0 +1,18 @@
+#import <UIKit/UIKit.h>
+#import <Foundation/Foundation.h>
+#import "CMethodResult.h"
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif //__cplusplus
+
+void RubyCallbackHelper_callCallback(NSString* callbackURL,
+ CMethodResult* methodResult,
+ NSString* callbackParam
+ );
+
+
+#ifdef __cplusplus
+}
+#endif //__cplusplus
@@ -0,0 +1,73 @@
+
+#import "rubyext/WebView.h"
+#import "common/RhodesApp.h"
+#include "ruby/ext/rho/rhoruby.h"
+#include <string.h>
+#import "RubyCallbackHelper.h"
+
+class BarcodeRhoCallbackResultContainer : public rho::ICallbackObject
+{
+public:
+ BarcodeRhoCallbackResultContainer(CMethodResult* methodResult)
+ {
+ mMethodResult = methodResult;
+ }
+
+ virtual ~BarcodeRhoCallbackResultContainer() {
+ [mMethodResult release];
+ }
+
+ // return Ruby object
+ virtual unsigned long getObjectValue() {
+ return [mMethodResult toRuby];
+ }
+
+private:
+ CMethodResult* mMethodResult;
+
+};
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif //__cplusplus
+
+
+void RubyCallbackHelper_callCallback(NSString* callbackURL,
+ CMethodResult* methodResult,
+ NSString* callbackParam
+ ) {
+
+
+ NSString* strBody = @"&rho_callback=1";
+
+ strBody = [strBody stringByAppendingString:@"&"];
+
+ NSString* strParam = [NSString stringWithUTF8String:( RHODESAPP().addCallbackObject( new BarcodeRhoCallbackResultContainer(methodResult), "body").c_str() ) ];
+
+ strBody = [strBody stringByAppendingString:strParam];
+
+ if (callbackParam != nil) {
+ strBody = [strBody stringByAppendingString:callbackParam];
+ }
+
+ const char* cb = [callbackURL UTF8String];
+ const char* b = [strBody UTF8String];
+ char* norm_url = rho_http_normalizeurl(cb);
+
+ rho_net_request_with_data(rho_http_normalizeurl(cb), b);
+
+ rho_http_free(norm_url);
+
+
+
+
+}
+
+
+
+#ifdef __cplusplus
+ }
+#endif //__cplusplus
+
+
@@ -0,0 +1 @@
+Contain iOS helpers and classes (used for implementation of API on iOS platform)
@@ -1,4 +1,4 @@
-#include "..\Common\js_helpers.h"
+#include "../common/js_helpers.h"
#include "logging/RhoLog.h"
#undef DEFAULT_LOGCATEGORY
@@ -0,0 +1,34 @@
+
+#import <Foundation/Foundation.h>
+
+#import "../../../common/iphone/IMethodResult.h"
+
+@protocol IBarcode1 <NSObject>
+
+-(void) getProps:(id<IMethodResult>)methodResult;
+-(void) getPropsWithString:(NSString*)param1 methodResult:(id<IMethodResult>)methodResult;
+-(void) getPropsWithArray:(NSArray*)param1 methodResult:(id<IMethodResult>)methodResult;
+
+// NOTE: if you want to hold methodResult(for periodically call callback for example) you should release it buself when you stop using it !
+
++(void) enumerate:(id<IMethodResult>)methodResult;
+
+@end
+
+
+@protocol IBarcode1Factory <NSObject>
+
+-(id<IBarcode1>) getBarcode1ByID:(NSString*)ID;
+-(NSString*) getDefaultID;
+-(void) setDefaultID:(NSString*)defaultID;
+-(NSString*)getInitialDefaultID;
+-(Class) getBarcode1ImplementationClass;
+
+@end
+
+@interface Barcode1Singletone : NSObject {
+}
+
++(id<IBarcode1Factory>) getBarcode1Factory;
+
+@end
@@ -0,0 +1,2 @@
+contains generated files with module API.
+PLEASE DO NOT MODIFY THIS FILES !!!
Oops, something went wrong.

0 comments on commit 6474748

Please sign in to comment.