Разработка кросс-платформенного кода между iphone < ->...
TRANSCRIPT
Cross-platform developmentfor
iPhone
Contributor: Tovchenko Taras(Doctor Set)
Plan
• What is cross-platform development
• Benefits & Expenses
• Implementation - 2 ways
• Use open source libraries
• A&Q
What does this mean “cross-platform”?
2. Business logic 1. GUI
GUI porting is very bag applicable from iPhone to desktop platforms
- ?
How we can distribute business logic?
1. Base logic - memory, containers, etc.
2. Logic of your application
3. Graphic output (OpenGL, convertors)
4. Audio output (OpenAL)
5. Databases
What applications we can create full cross-platform and what can be created
particles?
1. (Full) Games - 60% at all iPhone applications
2. (Medium) Scientific applications which use graphic output - medical, engineering, etc.
3. (Not applicable) Applications based on iPhone GUI
Expenses1. If you write 2 applications = you pay x2 $
2. Or you can write 1 application for 2 markets = x1.1 - x1.7 $
Several paths for attainment cross-platform
• Porting existing code
• Write new code than will be oriented to cross-platform
PortingIf you have already wrote project - use this method
Problems
1. Existing code wrote on language which not compile on other platforms, often this is Objective-C
2. On a project was used system depended api (on iPhone this is POSIX)
3. GUI - which can’t be ported automatically to other platforms
Solutions
• For problem with code we can use some emulators of objective-c code - qobjc runtime, cocotron library.
• For system api we can writes wrappers than will be defined on concrete platform.
• GUI - for better case need redesign, for second case you can write some automatic engine for your dialogs.
Open Source libraries
• For code porting (objc) currently we don’t have optimal solutions. Almost all libraries designed for Windows <-> Mac OS but not for iPhone.
But we can use its for:
1. Learning and looking to its implementations
2. Improve this libraries for iPhone
Solutions for code porting
Lib name License Compiler
Cocotron MIT GCC
GNUStep GPL GCC
qobjc Author’s, GPL Visual Studio
qobjc (quick)
Scientific project, this is worked, tested runtime of Objective-C language
Problem: this is only runtime lib, but for full functionality need code parser
http://code.google.com/p/qobjc
Q_BEGIN_CLASS(MyDecl, BaseClass) Q_INCLUDE_PROTOCOL_TO_CLASS(QMyProto2) Q_BEGIN_IVAR_LIST Q_DEF_IVAR(_someInt, i) Q_DEF_IVAR(_someDouble, d) Q_DEF_IVAR(_someFloat, f) Q_END Q_BEGIN_INSTANCE_METHOD_LIST Q_DEF_METHOD(calculateArea:, _calcAreaXY, +f+f+f+d+f+f) Q_DEF_METHOD(dealloc, _dealloc1, +v) Q_END_INSTANCE_METHOD_LIST Q_END_CLASS
@interface MyDecl : BaseClass <QMyProto2> { int _someInt; double _someDouble; float _someFloat;}
- (float)calculateArea:(float)v0 :(float)v1 :(double)v2 :(float)v3 :(float)v4;- (void)dealloc; // in objective-c this method not need declare on header :)
Objective-C
Macro code on qobjc
New Code
What benefits?
We can write code on already portable language as - C++, and some scripting
languages - LUA, PostScript
For implementing system API uses libraries (mostly C++) which wraps this
work - example dCocoa, QT
- ?Objective-C
(speciality 2.0) is not cross-platform
dCocoa
Author’s library for cross-platform implementation business logics for iPhone and with possibility run or develop this logic on Windows platform.
http://code.google.com/p/dcocoa
LGPL license
What give your dCocoa now?
1. Convenient Objective-C mechanisms emulation. This library writes on C++ and approximates to Foundation framework with almost all objc-runtime features.
2. Cross-platform between iPhone <-> Windows
1. Keep meta-information
2. Memory management (retain count, autorelease pools)
3. Containers (array, set, dictionary) in 2 form - for standard C++ types and dcocoa types
4. System dependent features (threads, TLS, timer, run-loop, etc)
5. Other helper classes (such as invocation, etc)
Objective-C
@interface MyClass : NSObject {}+ (void)method1;- (void)method2;
void func() { NSAutoreleasePool* pool = [[NSAutorelease alloc] init];
id obj = [[MyClass alloc] initWith:5];
[_someObject addTarget:obj selector:@selector(method2)];
[obj release];[pool release];}
dCocoa
class MyClass : public CL::dObject {COCOA_CLASS_DECLARE(MyClass)typedef CL::dObject _super;public: virtual MyClass* initWith(t a); void method1(); // or virtual
METHOD_DECLARE(method2) // meta};void func() { _LocalPool
CL::dObject* obj = MyClass::alloc()->initWith(5); _someObject->addTargetSelector( obj, dselector(method2));
CoRelease(obj);}
A&Q
Written by Taras Tovcheko, 2009/07/18e-mail: [email protected]