370 likes | 388 Views
Discover the power of Windows Runtime for building responsive, fluid Metro style apps. Learn about the core concepts, projection into languages, and the Windows Runtime contract.
E N D
The Windows Runtime Martyn Lovell Development ManagerWindows Runtime Experience Microsoft Corporation
Agenda • What is the Windows Runtime? • The Windows Runtime Contract • Projecting into Languages • Call to Action
The Windows 8 Developer Experience The Windows Runtime is the solid, efficient foundation for building great Metro style apps • Easy to build a Metro style app • Dramatic improvements in developer experience • Freedom of choice – language, library, markup • Enabing a new generation of fast, fluid, responsive apps
Major improvement to developer experience Great intellisense& tooling Native, Managed, Dynamic all first-class citizens JavaScript, C#/VB and C++ initial targets Platform based Versioning Apps keep running on future Windows versions Simple low-level constructs; usability in projection Responsive and Fluid Apps Async APIs where they are needed Well-designed, consistent objects API surface is clear and consistent Design Principles
Metro style application APIs User Interface HTML5/CSS XAML DirectX Controls Data Binding SVG Tiles Input Accessibility Printing Devices Communications & Data Web Contracts Geolocation Portable Sensors NFC Local & Cloud Storage Streams Notifications Media SMS Background Transfer XML Networking Visual Effects Playback Capture PlayTo Fundamentals Application Services Threading/Timers Memory Management Authentication Cryptography Globalization
Windows Runtime Architecture Windows 8 “Metro style” app Language Support (CLR, WinJS, CRT) Language Projection (Generated from Metadata) Web Host (HTML, CSS, JavaScript)) Windows Metadata & Namespace UI Pickers Controls Media XAML Storage Network … Windows Runtime Core Runtime Broker Windows Core
What is a Windows Runtime Object? Shell32.dll IInspectable IUnknown IStorageItemInformation Object IStorageItem FileInformation Runtime Class IStorageFile Interfaces Windows Metadata (Disk) Activation Store
Collections IInspectable IUnknown IVector<T> Array IVectorView<T> IObservableVector<T> IInspectable IUnknown IMap<T> Associative Collection IMapView<T> IObservableMap<T>
Windows Metadata • Concise, complete description of the Windows Runtime • Full description of Windows ships in SDK and on system • Use to describe your objects • Generated natively from C++ or C#/VB Compiler • Efficient binary format derived CLI Metadata • Profile of ECMA 335, Partition II • Same structures, different meanings • Readable by existing tools • Rich enough to allow multi-language projection generation • Full intellisense on statically known information
Versioning IInspectable IInspectable IUnknown IUnknown Future Windows Windows 8 Object Object Windows Metadata v8 App Windows Metadata v9 App Projection Projection
Asynchronous Objects • Basic requirement for Metro style apps • Always responsive, ready • “Long running” APIs must be delivered as async • Simpler to allow apps to make synchronous calls • But then bad apps can overwhelm quality of system • Instead, build async into API shape • And have language projections integrate it deeply • Async protocol is low-level • Language projection provides simplified high level view
Threading App Threadpool Main UI Thread Windows UI Object Windows Object Windows Object App Code App Code App Code
Three main types of object Thread bound – works only on the thread where it was created – most UI Thread flexible – direct call and works on any thread, uses locking if needed to control simultaneous access – most others Brokered – out of process for resource protection UI runs in single threaded environment that is not reentrant (“Application STA”) Callbacks can only enter if they are related to an outgoing call Most non-UI runs in any thread Windows Runtime Threading
The Windows Namespace • Windows.* Runtime objects are in a simple, unified, hierarchical namespace • Great intellisense and browsing in Visual Studio • One Clear type for each function • Catalogis extensible but private • Your apps can add objects • Only visible in your app • Objects can be seen from any language
Projections C++ App Projection IInspectable IUnknown Object C#/VB App CLR Projection HTML App JS Chakra Projection Windows Metadata
Projections • Projections make Windows Runtime APIs natural and familiar in every language. • Automatically generated at compile/run time • Ensures you don’t wait for language/framework to catch up • Windows exposes simple concepts – interfaces, functions • Metadata shows how they compose • Patterns allow projections to adapt • Examples: classes, events, delegates, async and collections • Each language expresses patterns differently • Uses styles that are natural and familiar to their developers
Language Integration • Will the Windows Runtime be at home in each language? • Yes, but never perfectly • Many aspects can adapt well • object creation • collections • Naming typography(pascal vs.. camel vs. lower) • Return value usage
Language Integration • Some other aspects must match function • Parameter ordering • Concept naming (e.g. file vs. item) • Great interop with language types possible • Depends on work from language teams • Some overlap/duplication inevitable • Some language semantics are more foreign • We have side-effects, so functional language integration less natural • Overlap with standard libraries inevitable • Projection can reduce (e.g. System::String vs HSTRING) • Some will remain (e.g. XML)
Designing your projection • Map type systems • 2 Way mapping for basic types • Carefully consider round-trip typing • Map patterns and abstractions • Ensure your users collections can be passed to Windows • Fit delegates/events into your call-back model • Integrate threading and async • Project async in simple way • Consider promise/future approach • Critical step to get this right
Designing your projection • Harmonize object lifetime • Windows Runtime objects deterministic • Consider proxy object approach for GC languages • Like CLR’s RCW/CCW. • Take account of ICloseable semantics. • Plan shutdown carefully • Consider versioning • Windows Runtime versions like the operating system • Binary compatible • Additive • Users need to tell compiler/projection what version of platform they are targeting
Implementing your Projection • Handle Errors • Windows Runtime is HRESULT error code based • Expected to map to exceptions in most languages • Read and write Metadata • Must Use our APIs to read metadata • We will reorganise on-disk naming and structure • Only way to correctly find all metadata for a type • Ensure your written metadata is conformant • Bind to types • Use type resolution APIs to load metadata
Implementing Your Projection • Adjust Standard Library • Can only use Metro style APIs – e.g. No Console! • Obscure types with natural analogues • Don’t expose a Windows type with a tight mapping to a language type • E.g. hideWinRT’sstring, int32 • Do expose if there are important semantic differences. • Ensure efficient behaviour at projection boundary • Don’t copy strings (pass by ref – we allow) • Don’t copy collections
Windows Runtime in JavaScript • function peerFinder_AcceptRequest() { • // Accept the connection if the user clicks okay. • ProximityHelpers.displayStatus("Connecting to " + requestingPeer.displayName + " ..."); • ProximityHelpers.id("peerFinder_AcceptRequest").style.display = "none"; • ProxNS.PeerFinder.connectAsync(requestingPeer).then( • function (proximitySocket) { • ProximityHelpers.displayStatus("Connect to " + requestingPeer.displayName + " succeeded"); • startSendReceive(proximitySocket); • }, • function (err) { • ProximityHelpers.displayError("Connect to " + requestingPeer.displayName + " failed with " + err); • ProximityHelpers.id("peerFinder_Connect").style.display = "none"; • }); • }
Windows Runtime in C# • async privatevoid PeerFinder_Accept(object sender, RoutedEventArgs e) • { • rootPage.NotifyUser("", NotifyType.ErrorMessage); • rootPage.NotifyUser("Connecting to " + _requestingPeer.DisplayName + "....", NotifyType.StatusMessage); • PeerFinder_AcceptButton.Visibility = Visibility.Collapsed; • try • { • _socket = await PeerFinder.ConnectAsync(_requestingPeer); • rootPage.NotifyUser("Connection succeeded", NotifyType.StatusMessage); • PeerFinder_StartSendReceive(); • } • catch (Exception err) • { • rootPage.NotifyUser("Connection to " + _requestingPeer.DisplayName + " failed: " + err.Message, NotifyType.ErrorMessage); • } • }
Windows Runtime in C++ • void PeerFinderScenario::PeerFinder_Accept(Object^ sender, RoutedEventArgs^ e) { • m_rootPage->NotifyUser("", NotifyType::ErrorMessage); • m_rootPage->NotifyUser("Connecting to " + m_requestingPeer->DisplayName + "....", NotifyType::StatusMessage); • PeerFinder_AcceptButton->Visibility = Visibility::Collapsed; • auto op = PeerFinder::ConnectAsync(m_requestingPeer); • Concurrency::task<StreamSocket^> connectTask(op); • connectTask.then([this](Concurrency::task<StreamSocket^> resultTask) { • try { • m_socket = resultTask.get(); • m_rootPage->NotifyUser("Connection succeeded", NotifyType::StatusMessage); • PeerFinder_StartSendReceive(); • } • catch(Exception^ e) { • m_rootPage->NotifyUser("Connection to " + m_requestingPeer->DisplayName + " failed: " + e->Message, NotifyType::ErrorMessage); • } • }); • }
Call to Action • The Windows Runtime is the solid, efficient foundation for the new Windows 8 developer platform • Build Metro style apps easily with the Windows Runtime • Windows available in your choice of language and environment • Bring your language to the Windows runtime • Create a language projection • Make Windows a natural and familiar part of your world • We can engage and help
Q&A • http://msdn.microsoft.com/windows • Email:martynl@microsoft.com • Windows 8: http://channel9.msdn.com/Events/BUILD/BUILD2011/KEY-0001 • Platform: http://channel9.msdn.com/Events/BUILD/BUILD2011/BPS-1005 • Windows Runtime: http://channel9.msdn.com/Events/BUILD/BUILD2011/PLAT-874T • Internals: http://channel9.msdn.com/Events/BUILD/BUILD2011/PLAT-875T
Windows 8 Metro style Apps Desktop Apps HTML JavaScript HTML / CSS XAML View JavaScript (Chakra) C/C++ C#, VB Model Controller C C++ C# VB WinRT APIs Devices & Printing Communication & Data Graphics & Media System Services .NET SL Internet Explorer Win32 Application Model Windows Core OS Services Core
Brokered Objects RuntimeBroker.exe App Proxy Projection IInspectable IUnknown Object