Date post: | 21-Dec-2015 |
Category: |
Documents |
View: | 217 times |
Download: | 2 times |
A Unified Approach for Cross-A Unified Approach for Cross-Platform Software Platform Software
DevelopmentDevelopment
A Master’s defenseA Master’s defense
ByBy
Jeffery Alan StuartJeffery Alan Stuart
AcknowledgementsAcknowledgements
My advisor, Dr. HarrisMy advisor, Dr. Harris
My Committee, Dr. Dascalu, Dr. Johnson, My Committee, Dr. Dascalu, Dr. Johnson,
DeannaDeanna
Peers (Joe, Lance)Peers (Joe, Lance)
OutlineOutline
DefinitionsDefinitions IntroductionIntroductionBackgroundBackgroundMy IdeaMy Idea Implementation of my IdeaImplementation of my IdeaDirections for Future WorkDirections for Future WorkConclusionsConclusions
DefinitionsDefinitions
Hardware PlatformHardware PlatformSoftware PlatformSoftware PlatformApplication Programming Interface (API)Application Programming Interface (API)Cross-Platform API (Library)Cross-Platform API (Library)
IntroductionIntroduction
Why cross-platform APIs?Why cross-platform APIs?
Why is it hard?Why is it hard?
IntroductionIntroduction
Current methods (more detail later)Current methods (more detail later)PreprocessorPreprocessorSeparate BranchesSeparate Branches
BackgroundBackground
Cross-platform used to “not exist”Cross-platform used to “not exist”
UNIX KernelUNIX Kernel
Make (~1970)Make (~1970)
BackgroundBackground
Two (current) widely-used methodsTwo (current) widely-used methodsPreprocessorPreprocessor
#ifdef _WIN32#ifdef _WIN32#ifdef __POSIX#ifdef __POSIX
Development branchesDevelopment branchesQt_Win32_4.0.0.b.src.zipQt_Win32_4.0.0.b.src.zipQt_X11_4.0.0.b.src.tar.gzQt_X11_4.0.0.b.src.tar.gz
BackgroundBackground
PreprocessorPreprocessorUsed to eliminate non-compatible code at Used to eliminate non-compatible code at
compile timecompile timeHard to readHard to readSeveral “smaller” packagesSeveral “smaller” packages
Boost ThreadsBoost ThreadsHawkNLHawkNLMsgConnectMsgConnectZThreadsZThreads
BackgroundBackground
Why hard to read?Why hard to read?
Code separatedCode separated
Some programmers not familiar with Some programmers not familiar with preprocessor macrospreprocessor macros
BackgroundBackground
Boost threadsBoost threadsThreading package (C++ [stdc++])Threading package (C++ [stdc++])Conditionally includes member variables in Conditionally includes member variables in
structures (really bad!)structures (really bad!)Why?Why?
BackgroundBackground
HawkNLHawkNLNetworking library (C)Networking library (C)Preprocessor usedPreprocessor used
for typedefs andfor typedefs and
macrosmacrosStill confusing, hardStill confusing, hard
to find #definesto find #defines
BackgroundBackground
MsgConnectMsgConnectNetworking API (C++)Networking API (C++)Preprocessor used for typedefs and macrosPreprocessor used for typedefs and macros
Tries to port Win32 API to Linux (bad)Tries to port Win32 API to Linux (bad)
BackgroundBackground
ZThreadsZThreadsThreading API (C++)Threading API (C++)
Conditionally include platform implementationsConditionally include platform implementationsNot necessarily obvious what platform is being Not necessarily obvious what platform is being
usedusedHow to change easily (pthreads for windows)?How to change easily (pthreads for windows)?
BackgroundBackground
Separate BranchesSeparate BranchesAll platform specific code (sometimes all All platform specific code (sometimes all
code!) in different branchescode!) in different branchesEasy to read, hard to shareEasy to read, hard to share ““Larger” packages tend to use thisLarger” packages tend to use this
OpenSGOpenSGQtQtGTKGTKPOSIX ThreadsPOSIX Threads
BackgroundBackground
Several side effectsSeveral side effectsMinimizes code sharingMinimizes code sharingSometimes platform-specific access is Sometimes platform-specific access is
granted (e.g. Qt’s QWidget)granted (e.g. Qt’s QWidget)Changing design often has unbalanced Changing design often has unbalanced
consequences across branchesconsequences across branches
BackgroundBackground
Design patternsDesign patternsCreational patternsCreational patternsStructural patternsStructural patternsBehavioral patternsBehavioral patterns
Important to new idea:Important to new idea:BridgeBridgeBuilderBuilderAbstract FactoryAbstract Factory
Is There A Better Way?Is There A Better Way?
Aren’t the two methods enough?Aren’t the two methods enough?Maintain readability and maximize code Maintain readability and maximize code
sharingsharingAnd the new ideas are…And the new ideas are…
““Cores”Cores” ““Routers”Routers”
CoresCores
Generic “solution”Generic “solution”Name has significanceName has significanceComposition (Inheritance + Aggregation)Composition (Inheritance + Aggregation)When to use/not-useWhen to use/not-use
Platform-specific data membersPlatform-specific data membersPlatform-specific operationsPlatform-specific operationsDiagram shown belowDiagram shown below
RoutersRouters
Generic “solution”Generic “solution”Dependency (No real need for inheritance)Dependency (No real need for inheritance)When to useWhen to use
Platform-specific operationsPlatform-specific operationsWhy? Don’t cores work?Why? Don’t cores work?
Core ExampleCore Example
Platform-Independent Thread classPlatform-Independent Thread classHas platform-dependent and platform-Has platform-dependent and platform-
independent data membersindependent data membersHas platform-dependent and platform-Has platform-dependent and platform-
independent operationsindependent operationsFor brevity, the class will be minimally For brevity, the class will be minimally
functionalfunctional
Core ExampleCore Example
Thread FileThread FileHas a “core”Has a “core”Relays platform-specific operations to coreRelays platform-specific operations to core
Core ExampleCore Example
ThreadCore FileThreadCore FileVirtualVirtualNo platform-specific typesNo platform-specific typesNon-functionalNon-functional
Core ExampleCore Example
Platform-specific implementationPlatform-specific implementationWin32Win32
Core ExampleCore Example
Class Diagram for “Thread”Class Diagram for “Thread”
Router exampleRouter example
File ClassFile ClassName has signifiganceName has signifiganceOnly needs a string (char*, std::string) for Only needs a string (char*, std::string) for
statestatePlatform-dependent operations Platform-dependent operations
(GetFileAttributes, stat)(GetFileAttributes, stat)For brevity, minimal functionality onlyFor brevity, minimal functionality only
Router ExampleRouter Example
File… FileFile… FileNo “router” memberNo “router” member
Router ExampleRouter Example
FileRouter FileFileRouter FileNo virtual functionsNo virtual functionsPrimarily static functionsPrimarily static functionsConstructor/destructor not “necessary”Constructor/destructor not “necessary”
Router ExampleRouter Example
Platform-specific implementationPlatform-specific implementationWin32 ImplementationWin32 Implementation
Router ExampleRouter Example
Class diagram for “File”Class diagram for “File”
Real ImplementationReal Implementation
Cross-platform libraryCross-platform libraryThe “J” Toolkit (JTK)The “J” Toolkit (JTK)Uses cores and routersUses cores and routers
JTK PackagesJTK Packages
Needs to be broadNeeds to be broadSeveral packagesSeveral packages
Platform specifics a must (networking, OS Platform specifics a must (networking, OS related, hardware related)related, hardware related)
JTK Base packageJTK Base package
Foundation classes, C++ primitive Foundation classes, C++ primitive wrapperswrappers
JTK I/O PackageJTK I/O Package
Primitives for reading/writingPrimitives for reading/writingFile I/O, File Descriptors, PipesFile I/O, File Descriptors, Pipes
JTK Media PackageJTK Media Package
Provides media access (Sound card, etc.)Provides media access (Sound card, etc.)Show that cores are good for wrapping Show that cores are good for wrapping
access to hardware, not just softwareaccess to hardware, not just software
JTK Networking PackageJTK Networking Package
Networking utilities (Sockets, Address Networking utilities (Sockets, Address lookup/translation)lookup/translation)
JTK OS PackageJTK OS Package
Operating System primitives (Threads, Operating System primitives (Threads, Semaphores)Semaphores)
Interface to OS for applicationsInterface to OS for applications
JTK Utilities PackageJTK Utilities Package
Cores can be used for more than just Cores can be used for more than just cross-platform classescross-platform classesSpecific implementations, optimizationsSpecific implementations, optimizations
ApplicationApplication
MotiviationMotiviationUse JTKUse JTKUse platform-dependent servicesUse platform-dependent servicesUse hardware servicesUse hardware servicesCode lengthCode lengthCode readabilityCode readability
ApplicationApplication
Two applications actually…Two applications actually…
PCM (Wave-file) player and ServerPCM (Wave-file) player and Server
PCM ServerPCM Server
““Serve” files to clientServe” files to clientMulti-threadedMulti-threadedNetworked (TCP and UDP)Networked (TCP and UDP)Streams audioStreams audioFlow chart on next pageFlow chart on next page
PCM ServerPCM Server
Just as readable as with other APIs (e.g. Just as readable as with other APIs (e.g. Qt)Qt)No preprocessor statements (besides No preprocessor statements (besides
includes)includes)~350 Lines~350 Lines
Platform specific implementations at least 2-3 Platform specific implementations at least 2-3 times largertimes larger
PCM ClientPCM Client
Streams PCM data from serverStreams PCM data from serverSingle-threadedSingle-threadedNetworked (TCP and UDP)Networked (TCP and UDP)Uses jtk::media::AudioDevice (sound card Uses jtk::media::AudioDevice (sound card
access)access)Flow chart on next pageFlow chart on next page
PCM ClientPCM Client
Very concise and readableVery concise and readableNo preprocessor statements (besides No preprocessor statements (besides
includes)includes)~250 Lines~250 Lines
Future WorkFuture Work
Compiler OptimizationsCompiler Optimizations
Extend/Enhance JTKExtend/Enhance JTK
New programming environmentNew programming environment
Common API across platforms (…)Common API across platforms (…)
ConclusionsConclusions
Even though OOP is popular, imperative Even though OOP is popular, imperative programming habits stick aroundprogramming habits stick around
Cores and routers are innovative and Cores and routers are innovative and helpfulhelpful
Readability is (near) optimalReadability is (near) optimalCode sharing is (near) optimalCode sharing is (near) optimal
Q&AQ&A