Download presentation
Presentation is loading. Please wait.
1
A Unified Approach for Cross- Platform Software Development A Master’s defense By Jeffery Alan Stuart
2
Acknowledgements My advisor, Dr. Harris My advisor, Dr. Harris My Committee, Dr. Dascalu, Dr. Johnson, My Committee, Dr. Dascalu, Dr. Johnson, Deanna Deanna Peers (Joe, Lance) Peers (Joe, Lance)
3
Outline Definitions Definitions Introduction Introduction Background Background My Idea My Idea Implementation of my Idea Implementation of my Idea Directions for Future Work Directions for Future Work Conclusions Conclusions
4
Definitions Hardware Platform Hardware Platform Software Platform Software Platform Application Programming Interface (API) Application Programming Interface (API) Cross-Platform API (Library) Cross-Platform API (Library)
5
Introduction Why cross-platform APIs? Why cross-platform APIs? Why is it hard? Why is it hard?
6
Introduction Current methods (more detail later) Current methods (more detail later) Preprocessor Preprocessor Separate Branches Separate Branches
7
Background Cross-platform used to “not exist” Cross-platform used to “not exist” UNIX Kernel UNIX Kernel Make (~1970) Make (~1970)
8
Background Two (current) widely-used methods Two (current) widely-used methods Preprocessor Preprocessor #ifdef _WIN32 #ifdef _WIN32 #ifdef __POSIX #ifdef __POSIX Development branches Development branches Qt_Win32_4.0.0.b.src.zip Qt_Win32_4.0.0.b.src.zip Qt_X11_4.0.0.b.src.tar.gz Qt_X11_4.0.0.b.src.tar.gz
9
Background Preprocessor Preprocessor Used to eliminate non-compatible code at compile time Used to eliminate non-compatible code at compile time Hard to read Hard to read Several “smaller” packages Several “smaller” packages Boost Threads Boost Threads HawkNL HawkNL MsgConnect MsgConnect ZThreads ZThreads
10
Background Why hard to read? Why hard to read? Code separated Code separated Some programmers not familiar with preprocessor macros Some programmers not familiar with preprocessor macros
11
Background Boost threads Boost threads Threading package (C++ [stdc++]) Threading package (C++ [stdc++]) Conditionally includes member variables in structures (really bad!) Conditionally includes member variables in structures (really bad!) Why? Why?
12
Background HawkNL HawkNL Networking library (C) Networking library (C) Preprocessor used Preprocessor used for typedefs and macros macros Still confusing, hard Still confusing, hard to find #defines
13
Background MsgConnect MsgConnect Networking API (C++) Networking API (C++) Preprocessor used for typedefs and macros Preprocessor used for typedefs and macros Tries to port Win32 API to Linux (bad) Tries to port Win32 API to Linux (bad)
14
Background ZThreads ZThreads Threading API (C++) Threading API (C++) Conditionally include platform implementations Conditionally include platform implementations Not necessarily obvious what platform is being used Not necessarily obvious what platform is being used How to change easily (pthreads for windows)? How to change easily (pthreads for windows)?
15
Background Separate Branches Separate Branches All platform specific code (sometimes all code!) in different branches All platform specific code (sometimes all code!) in different branches Easy to read, hard to share Easy to read, hard to share “Larger” packages tend to use this “Larger” packages tend to use this OpenSG OpenSG Qt Qt GTK GTK POSIX Threads POSIX Threads
16
Background Several side effects Several side effects Minimizes code sharing Minimizes code sharing Sometimes platform-specific access is granted (e.g. Qt’s QWidget) Sometimes platform-specific access is granted (e.g. Qt’s QWidget) Changing design often has unbalanced consequences across branches Changing design often has unbalanced consequences across branches
17
Background Design patterns Design patterns Creational patterns Creational patterns Structural patterns Structural patterns Behavioral patterns Behavioral patterns Important to new idea: Important to new idea: Bridge Bridge Builder Builder Abstract Factory Abstract Factory
18
Is There A Better Way? Aren’t the two methods enough? Aren’t the two methods enough? Maintain readability and maximize code sharing Maintain readability and maximize code sharing And the new ideas are… And the new ideas are… “Cores” “Cores” “Routers” “Routers”
19
Cores Generic “solution” Generic “solution” Name has significance Name has significance Composition (Inheritance + Aggregation) Composition (Inheritance + Aggregation) When to use/not-use When to use/not-use Platform-specific data members Platform-specific data members Platform-specific operations Platform-specific operations Diagram shown below Diagram shown below
20
Routers Generic “solution” Generic “solution” Dependency (No real need for inheritance) Dependency (No real need for inheritance) When to use When to use Platform-specific operations Platform-specific operations Why? Don’t cores work? Why? Don’t cores work?
21
Core Example Platform-Independent Thread class Platform-Independent Thread class Has platform-dependent and platform- independent data members Has platform-dependent and platform- independent data members Has platform-dependent and platform- independent operations Has platform-dependent and platform- independent operations For brevity, the class will be minimally functional For brevity, the class will be minimally functional
22
Core Example Thread File Thread File Has a “core” Has a “core” Relays platform-specific operations to core Relays platform-specific operations to core
23
Core Example ThreadCore File ThreadCore File Virtual Virtual No platform-specific types No platform-specific types Non-functional Non-functional
24
Core Example Platform-specific implementation Platform-specific implementation Win32 Win32
25
Core Example Class Diagram for “Thread” Class Diagram for “Thread”
26
Router example File Class File Class Name has signifigance Name has signifigance Only needs a string (char*, std::string) for state Only needs a string (char*, std::string) for state Platform-dependent operations (GetFileAttributes, stat) Platform-dependent operations (GetFileAttributes, stat) For brevity, minimal functionality only For brevity, minimal functionality only
27
Router Example File… File File… File No “router” member No “router” member
28
Router Example FileRouter File FileRouter File No virtual functions No virtual functions Primarily static functions Primarily static functions Constructor/destructor not “necessary” Constructor/destructor not “necessary”
29
Router Example Platform-specific implementation Platform-specific implementation Win32 Implementation Win32 Implementation
30
Router Example Class diagram for “File” Class diagram for “File”
31
Real Implementation Cross-platform library Cross-platform library The “J” Toolkit (JTK) The “J” Toolkit (JTK) Uses cores and routers Uses cores and routers
32
JTK Packages Needs to be broad Needs to be broad Several packages Several packages Platform specifics a must (networking, OS related, hardware related) Platform specifics a must (networking, OS related, hardware related)
33
JTK Base package Foundation classes, C++ primitive wrappers Foundation classes, C++ primitive wrappers
34
JTK I/O Package Primitives for reading/writing Primitives for reading/writing File I/O, File Descriptors, Pipes File I/O, File Descriptors, Pipes
35
JTK Media Package Provides media access (Sound card, etc.) Provides media access (Sound card, etc.) Show that cores are good for wrapping access to hardware, not just software Show that cores are good for wrapping access to hardware, not just software
36
JTK Networking Package Networking utilities (Sockets, Address lookup/translation) Networking utilities (Sockets, Address lookup/translation)
37
JTK OS Package Operating System primitives (Threads, Semaphores) Operating System primitives (Threads, Semaphores) Interface to OS for applications Interface to OS for applications
38
JTK Utilities Package Cores can be used for more than just cross-platform classes Cores can be used for more than just cross-platform classes Specific implementations, optimizations Specific implementations, optimizations
39
Application Motiviation Motiviation Use JTK Use JTK Use platform-dependent services Use platform-dependent services Use hardware services Use hardware services Code length Code length Code readability Code readability
40
Application Two applications actually… Two applications actually… PCM (Wave-file) player and Server PCM (Wave-file) player and Server
41
PCM Server “Serve” files to client “Serve” files to client Multi-threaded Multi-threaded Networked (TCP and UDP) Networked (TCP and UDP) Streams audio Streams audio Flow chart on next page Flow chart on next page
43
PCM Server Just as readable as with other APIs (e.g. Qt) Just as readable as with other APIs (e.g. Qt) No preprocessor statements (besides includes) No preprocessor statements (besides includes) ~350 Lines ~350 Lines Platform specific implementations at least 2-3 times larger Platform specific implementations at least 2-3 times larger
44
PCM Client Streams PCM data from server Streams PCM data from server Single-threaded Single-threaded Networked (TCP and UDP) Networked (TCP and UDP) Uses jtk::media::AudioDevice (sound card access) Uses jtk::media::AudioDevice (sound card access) Flow chart on next page Flow chart on next page
46
PCM Client Very concise and readable Very concise and readable No preprocessor statements (besides includes) No preprocessor statements (besides includes) ~250 Lines ~250 Lines
47
Future Work Compiler Optimizations Compiler Optimizations Extend/Enhance JTK Extend/Enhance JTK New programming environment New programming environment Common API across platforms (…) Common API across platforms (…)
48
Conclusions Even though OOP is popular, imperative programming habits stick around Even though OOP is popular, imperative programming habits stick around Cores and routers are innovative and helpful Cores and routers are innovative and helpful Readability is (near) optimal Readability is (near) optimal Code sharing is (near) optimal Code sharing is (near) optimal
49
Q&A
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.