+ All Categories
Home > Documents > A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan...

A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan...

Date post: 21-Dec-2015
Category:
View: 217 times
Download: 2 times
Share this document with a friend
49
A Unified Approach for A Unified Approach for Cross-Platform Cross-Platform Software Development Software Development A Master’s defense A Master’s defense By By Jeffery Alan Stuart Jeffery Alan Stuart
Transcript
Page 1: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

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

Page 2: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery 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)

Page 3: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

OutlineOutline

DefinitionsDefinitions IntroductionIntroductionBackgroundBackgroundMy IdeaMy Idea Implementation of my IdeaImplementation of my IdeaDirections for Future WorkDirections for Future WorkConclusionsConclusions

Page 4: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

DefinitionsDefinitions

Hardware PlatformHardware PlatformSoftware PlatformSoftware PlatformApplication Programming Interface (API)Application Programming Interface (API)Cross-Platform API (Library)Cross-Platform API (Library)

Page 5: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

IntroductionIntroduction

Why cross-platform APIs?Why cross-platform APIs?

Why is it hard?Why is it hard?

Page 6: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

IntroductionIntroduction

Current methods (more detail later)Current methods (more detail later)PreprocessorPreprocessorSeparate BranchesSeparate Branches

Page 7: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

BackgroundBackground

Cross-platform used to “not exist”Cross-platform used to “not exist”

UNIX KernelUNIX Kernel

Make (~1970)Make (~1970)

Page 8: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

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

Page 9: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

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

Page 10: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

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

Page 11: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

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?

Page 12: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

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

Page 13: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

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)

Page 14: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

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)?

Page 15: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

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

Page 16: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

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

Page 17: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

BackgroundBackground

Design patternsDesign patternsCreational patternsCreational patternsStructural patternsStructural patternsBehavioral patternsBehavioral patterns

Important to new idea:Important to new idea:BridgeBridgeBuilderBuilderAbstract FactoryAbstract Factory

Page 18: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

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”

Page 19: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

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

Page 20: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

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?

Page 21: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

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

Page 22: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

Core ExampleCore Example

Thread FileThread FileHas a “core”Has a “core”Relays platform-specific operations to coreRelays platform-specific operations to core

Page 23: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

Core ExampleCore Example

ThreadCore FileThreadCore FileVirtualVirtualNo platform-specific typesNo platform-specific typesNon-functionalNon-functional

Page 24: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

Core ExampleCore Example

Platform-specific implementationPlatform-specific implementationWin32Win32

Page 25: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

Core ExampleCore Example

Class Diagram for “Thread”Class Diagram for “Thread”

Page 26: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

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

Page 27: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

Router ExampleRouter Example

File… FileFile… FileNo “router” memberNo “router” member

Page 28: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

Router ExampleRouter Example

FileRouter FileFileRouter FileNo virtual functionsNo virtual functionsPrimarily static functionsPrimarily static functionsConstructor/destructor not “necessary”Constructor/destructor not “necessary”

Page 29: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

Router ExampleRouter Example

Platform-specific implementationPlatform-specific implementationWin32 ImplementationWin32 Implementation

Page 30: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

Router ExampleRouter Example

Class diagram for “File”Class diagram for “File”

Page 31: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

Real ImplementationReal Implementation

Cross-platform libraryCross-platform libraryThe “J” Toolkit (JTK)The “J” Toolkit (JTK)Uses cores and routersUses cores and routers

Page 32: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

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)

Page 33: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

JTK Base packageJTK Base package

Foundation classes, C++ primitive Foundation classes, C++ primitive wrapperswrappers

Page 34: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

JTK I/O PackageJTK I/O Package

Primitives for reading/writingPrimitives for reading/writingFile I/O, File Descriptors, PipesFile I/O, File Descriptors, Pipes

Page 35: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

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

Page 36: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

JTK Networking PackageJTK Networking Package

Networking utilities (Sockets, Address Networking utilities (Sockets, Address lookup/translation)lookup/translation)

Page 37: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

JTK OS PackageJTK OS Package

Operating System primitives (Threads, Operating System primitives (Threads, Semaphores)Semaphores)

Interface to OS for applicationsInterface to OS for applications

Page 38: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

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

Page 39: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

ApplicationApplication

MotiviationMotiviationUse JTKUse JTKUse platform-dependent servicesUse platform-dependent servicesUse hardware servicesUse hardware servicesCode lengthCode lengthCode readabilityCode readability

Page 40: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

ApplicationApplication

Two applications actually…Two applications actually…

PCM (Wave-file) player and ServerPCM (Wave-file) player and Server

Page 41: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

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

Page 42: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.
Page 43: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

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

Page 44: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

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

Page 45: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.
Page 46: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

PCM ClientPCM Client

Very concise and readableVery concise and readableNo preprocessor statements (besides No preprocessor statements (besides

includes)includes)~250 Lines~250 Lines

Page 47: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

Future WorkFuture Work

Compiler OptimizationsCompiler Optimizations

Extend/Enhance JTKExtend/Enhance JTK

New programming environmentNew programming environment

Common API across platforms (…)Common API across platforms (…)

Page 48: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

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

Page 49: A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart.

Q&AQ&A


Recommended