Building Server Applications Using Objective C And Gn Ustep
-
Upload
wangii -
Category
Technology
-
view
1.643 -
download
0
Transcript of Building Server Applications Using Objective C And Gn Ustep
GNUstep Presentation
Building Server Applications using Objective-C and GNUstepNicola Pero, Fosdem 2009
Server Applications
Server Applications = programs with no GUI
In GNUstep, server applications are based on GNUstep-base.
GNUstep-base is the most complete and extensively polished and tested part of GNUstep ...
but is little known to the public.People often identify GNUstep only with the GUI framework/development environment.
Objective-C
it is a programming language
it is a strict superset of C it is C with some new additional constructs
C code compiles as Objective-C code
C libraries can be linked and used natively from Objective-C
it adds Object-Oriented features to CDefining classes
Implementing methods
Instantiating classes and objects
Invoking class and object methods
Protocols, categories, selectors, forwarding
Why is Objective-C so special ?
It is compatible with C libraries
Is is a simple extension of C
It is a hybrid between C and SmalltalkIt can be as fast as raw C if you avoid the object-oriented extensions
It can be as high-level and flexible as Smalltalk if you use the object-oriented extensions
It allows experienced programmers to mix different programming styles in the same program
It is extremely flexible
Powerful Foundation class library
Why use Objective-C for Server Applications ?
Very fast. You can freely mix it with C and even assembler if you need.
High-level language. Organize your server code using high-level, object-orientated design patterns.
Powerful Foundation library (GNUstep-base). The API originates from OpenStep and the implementation has been polished for 13+ years.
OpenStep API - Foundation Kit (1994)
Foundation KitNon-graphical classesRoot classes: NSObject, NSProxy
Basic data classes: NSString, NSNumber, NSData, NSNull
Collection classes: NSArray, NSDictionary, NSSet
Execution control classes: NSRunLoop, NSTimer, NSThread, NSLock
I/O classes: NSTask, NSFileHandle
Notification classes: NSNotification, NSDistributedNotification
Serialization classes: NSArchiver, NSCoder
Resource management classes: NSBundle, NSUserDefaults
Distributed Objects Classes: NSConnection, NSPort
And many more...
ApplicationFoundation KitApplication KitOperating SystemOS Graphical SystemObjective-C Runtime
GNUstep-base
ApplicationGNUstep BaseGNUstep GUIOperating System (Any!)Graphical System (Any!)GNU Objective-C Runtime
GNUstep Back
Server Applications what do you need ?
gcc-objcObjective-C compiler
Objective-C runtime
gnustep-makeOfficial GNUstep Building System
Makefile library that automatically takes care of configuring and building on different platforms
gnustep-baseOpenStep Foundation Kit implementation
Provides core non-graphical Objective-C classes
Important dependencies
libffiRequired by gnustep-base
You may need to download it and install it from www.gnustep.org
libxmlRequired by gnustep-base
Install it from your GNU/Linux distribution
gnutls or opensslAllow gnustep-base to support https://
Install it from your GNU/Linux distribution
Typical Quick Installation (Ubuntu)
apt-get libgnustep-base-dev
Typical Manual Installation (RedHat)
yum install gcc-objc libxml-devel openssl-devel
wget ftp://sourceware.org/pub/libffi/libffi-3.0.1.tar.gztar xfvz libffi-3.0.1.tar.gzcd libffi-3.0.1./configuremakesu -c 'make install'
wget ftp://ftp.gnustep.org/pub/gnustep/core/gnustep-make-2.0.8.tar.gztar xfvz gnustep-make-2.0.8.tar.gzcd gnustep-make-2.0.8.tar.gz./configuremakesu -c 'make install'
. /usr/GNUstep/System/Library/Makefiles/GNUstep.sh
wget ftp://ftp.gnustep.org/pub/gnustep/core/gnustep-base-1.18.0.tar.gztar xfvz gnustep-base-1.18.0.tar.gzcd gnustep-base-1.18.0./configure enable-opensslmakesu -c 'make install'
Hello World! Program
Hello World using Objective-C / GNUstep-base
hello.m
#import
int main (void){ NSLog (@Hello world!); return 0;
}
Hello World! Program
Hello World using Objective-C / GNUstep-base
GNUmakefile
include $(GNUSTEP_MAKEFILES)/common.make
TOOL_NAME = hellohello_OBJC_FILES = hello.m
include $(GNUSTEP_MAKEFILES)/tool.make
Hello World! Program
Hello World using Objective-C / GNUstep-base
Usual compilation commands
make
make clean
make distclean
make install
make messages=yes
make install messages=yes
Hello World! Program
Hello World using Objective-C / GNUstep-base
Compilation results are in ./obj
Let's try it out: Tutorial Compilation Session
GNUstep-base coding: where to start
GNUstep Mini Tutorials (Introduction):
http://www.gnustep.it/nicola/Tutorials/index.html
GNUstep Base Documentation (API Reference):
http://www.gnustep.org/resources/documentation/Developer/Base/Reference/index.html
GNUstep-base coding: basic classes
Class cluster DesignTransparent way of optimizing classes without changing the public API
When you create a NSString or NSArray you actually get an instance of a subclass optimized to perform best in your situation
Method dispatch is dynamic, so that works
You can implement your own subclasses for performance
Mutable and non-mutable ClassesNSString vs NSMutableString
NSString is for constant strings that never change
NSMutableString is for strings that might change
Allows a lot of optimizations inside the library
GNUstep-base coding: basic classes
NSString, NSMutableStringString class
Full Unicode support
Class cluster implementation means ASCII strings are still extremely fast
Static strings
NSString *string = @This is a test string;
GNUstep-base coding: basic classes
NSArray, NSMutableArrayArray class
NSMutableArray provides arrays that grow dynamically
NSDictionary, NSMutableDictionaryHashtable/associative array class
NSMutableDictionary provides associative arrays that grow dynamically
{Name = Gorm.app;Description = GNUstep GUI Builder Application;}
(one, two, three);
GNUstep-base: Runloops and threads
NSRunLoopNSRunLoop
Event-based model
NSFileHandle
NSTimer
ThreadsNSThread
NSLock
GNUstep-base: Notifications
GNUstep-base supports notifications and observersFlexible way to connect objects
NSNotificationCenter
Objects can observe a notification and specify which methodthey want invoked when that notification is posted
Anything can post a notification
The notification is delivered to all observer
See NSNotificationCenter documentation for more information
GNUstep-base: Delegates
Objective-C and GNUstep-base encourage using delegates
A delegate allows you to extend a class without subclassing it
Subclassing can be heavy, and not that flexible
Delegates are more flexible you can delegate part of the code toan object of any class
-setDelegate: (NSObject *)delegate;-delegate;
GNUstep-base: Distributed Objects
Remote method invocation
High-level
You can expose objects in one process to other processes
Other processes can then contact the object and invoke methodsof the objects, as if they were local objects
Very natural to use
Excellent for building networks of processes that work cooperatively
See http://www.gnustep.it/nicola/Tutorials/ for a tutorial on Distributed Objects.
A look at some useful libraries
You can use any C library you want
Objective-C libraries provided by GNUstep check the dev-libs module in subversion
Objective-C libraries provided by other partiesSOPE (opengroupware.org)
Apple Cocoa non-GUI frameworks can sometime be used
GNUstep Database Libraries
You can use your own preferite C library
GNUstep Database LibrariesSQLClient
GDL2
SOPEThe best choice if you use the SOPE application server
Not so interesting if you're not
GNUstep Database Libraries
SQLClient
SQL Layer (low-level)Standard SQL layer to execute SQL queries/commands
Backend bundles (plugins) for the different databases (standard bundles: PostgreSQL, MySQL, SQLite, Oracle)
High-performance featuresConnection pooling
Advanced transaction support
Query caching
Update Batching
GNUstep Database Libraries
GDL2 (GNUstep Database Library v2)
High-level featuresSQL layer with EOAdaptors (plugins) for different database (standard bundles: PostgreSQL, SQLite)
Object-to-relationship mapping
Extensive use of KVC
Supports and encourages MVC patterns
Rapid development/integration supportEOInterface
DBModeler (GUI program)
GNUstep Database Libraries
SQLClientSQL only
You have to write your SQL code
Performance-oriented
Excellent for very high-performance servers where you write and tune each and every single SQL command
GDL2High-level framework
You works with models and objects you do not need to write SQL
Can be a bit hard to get into, but people love it once they get used to it
Excellent for large and properly structured OO projects
Performance is generally good
GNUstep WebServer Library
WebServer LibraryA library to implement quickly http/https server applications
Appropriate to develop efficient APIs for your system
Could be used for web pages but that is not the focus
Provides a full web server
Usually used with Apache in front as a reverse-proxy
Jigs: GNUstep Java Interface
What is itAllows you to use Objective-C libraries or objects from Java
And allows you to use Java libraries or objects from Objective-C
Objects and classes in Objective-C are mapped to objects andclasses in Java and vice versa
ProsIs very cool
ConsCan be slow, use it with moderation
Problems can be hard to debug
Limited support for cross-language subclassing
Not easy to port to other platforms
SOPE
An extensive set of frameworks
A complete Web application server environment
Apple WebObjects compatible app server extended with Zope concepts
XML processing (SAX2, DOM, XML-RPC)
MIME/IMAP4 processing
LDAP connectivity
RDBMS connectivity
iCalendar parsing
http://sope.opengroupware.org
Questions ?
Thank you
For more information
www.gnustep.org