Raw.githubusercontent.com



Introduction to the pmod SDK (Part1)C++ and native application development has very important role these days, the language, tools and frameworks has advanced enough to be still competitive against other popular languages/frameworks like Java, .NET, NodeJS. It may also happen that your company has big investment in the past on native code, but you must integrate your code with modern UI technologies in different platforms. This last task is sometimes very challenging on developers, they need to learn how to do it for each of the languages and environments and start taking care of string marshaling UTF-8 conversion, thread affinity, etc. How about dealing with event notifications back to the UI layer? As you can see C++/native developers face this problem in today’s world where most of the phone/desktop application is using WinRT/XAML technology on the Windows side, Cocoa framework on iOS and Google UI Interface on Android platform.Cross-platform projection library for C++ To address most of the problems described above there is good alternative to consider and is being published on GitHub recently ( HYPERLINK "" pmod SDK). The library itself was developed internally in Microsoft to address a real problem we faced when developing the Skype client for different platforms. Most of the ‘core’ stack was developed in C++, but the UI was constructed by separate team on the most efficient platform for each device. Each team end up writing a lot of additional code to allow the proper consumption on the target platform. This last step requires a lot of energy and also API changes on the ‘core’ stack was expensive making the approach very hard to sustain.What if we could develop a way were this ‘projection’ to other languages is much simpler and easy by allowing quick changes on the object model?Also, the projection semantic and naming convention is controlled by an automated tool that will always translate properly the different types supported and some of the intrinsic supported concept like asynchronous methods, enumerable types, array types, etc. Also, as I mention early the library allow intrinsic events to be fired like observable objects/collections and command state.The library was designed from the ground up to target in the most efficient way the Windows runtime platform but also to perform very well in other platforms.Building blocks of the SDKThe following diagram illustrate the different building blocks of the SDK including the runtime components, application authoring code, and code generated files.Blue are runtime components provided by the libraryIn green, you would notice the code generation tools and the generated code for your project that will be part of your projection User code is shown in white including your Application UI that is written in your favorite language My first pmod project walkthroughPart 1 of this blog will highlight one area of the library which is the schema definition and the projection results. Future topics will cover more advanced scenarios like data binding in other platforms and the reflection capabilities.For windows development, we recommend the use of VS 2017 as the IDE platform since the library has available Nuget packages that simplify the development process. For other platforms, we are looking on similar ways to allow better integration with XCode and Android Studio.Step 1.Start creating a regular Class Library project (.NET framework). This project will help you organize your model schema were your library will define all the supported types with methods and properties. You would rename the default file names.Step 2.Define a package source on your NuGet Tools->Options->Package Source dialog:This will help all your project to have access to the pmod NuGet packages available.Step 3. Add the ‘PMODCodeGenPackage’ from the ‘my pmod’ feed source. This will install the code generation tools needed to help you on your projects. The tool will produce multiple files, some of them projection files for each supported language and also authoring template to help you writing your portable code.Step 4:In your sample file add something like this into the content:namespace MyAppModel{ public interface IMyApp { string User { get; } void SignIn(string user, string pswd); }}This will define a simple entity that your code will later implement and will be projected to the different languages.Step 5:You would need to configure your C# project file and define a portable ‘schema definition’ file that is capable to run on MacOSx or Linux machine. Keep in mind the code generation tools can run also on different platforms.Drop this file into your project directory:You still need to configure the parameters to the underlying tools in your project file, by adding this section: <PropertyGroup> <ProductName>MyAppModel</ProductName> <ModelSchemaPath>$(MSBuildProjectDirectory)\MyAppModel.schema</ModelSchemaPath> <CodegenOutputDir>$(MSBuildProjectDirectory)\__generated</CodegenOutputDir> <JavaPackageName>com.microsoft.myapp</JavaPackageName> </PropertyGroup>At this point your project will be able to build and start the code generation that will the foundation of your projection and authoring helpers template.Exploring the projection filesIt is interesting to notice how your schema define your projection files, let’s explore each language on our ‘__generated’ folder.On WinRT the API will be defined as:namespace MyAppModel { [version(NTDDI_WIN8)] [uuid(c42e1386-936c-bdb6-5902-dee83ddb85b7)] interface IMyApp: IInspectable requires Microsoft.PropertyModel.IObservableObject { // Properties [propget] HRESULT User([out, retval] HSTRING* pValue); // MethodsHRESULT SignIn([in]HSTRING user,[in]HSTRING pswd); };}For Objective-C the projection will look like this:@protocol IMyApp <PMODObservableObject>-(NSString *) user;-(void) signIn:(NSString *) user pswd:(NSString *) pswd ;@endFor java it will project like this:package com.microsoft.myapp;public interface MyApp extends com.microsoft.pmod.ObservableObject { public String getUser(); public void signIn(String user,String pswd);}As you can see the code generation tools are producing code that you would include in your target platform to easily consume your code. You would also need to add the necessary runtime package available for each supported platform.Authoring your codeOn VS 2017 you would need to add a C++ Win32 project type and typically select the Dll option since you would need to access from other platforms. To have access into the SDK you would need to add a NuGet package selected from here:This will give you access to all public headers and proper linking libraries.Your final step would be to derive your class from the pre generated templates from the code gen step.Here is a snippet code on how to implement your IMyApp entity.class MyApp : public MyAppModel::_FastMyAppBase{protected:HRESULT SignInInternal(HSTRING user, HSTRING pswd) override{// your sign in code goes herereturn S_OK;}};This complete the steps on creating a model that will be accessible and able to project on other language and platforms. You would need to include your projection generated code and include the SDK runtime library support on your final application deployment. ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download