Code Monkey home page Code Monkey logo

device-management-bridge's Introduction

Windows IoT Core Device Management Bridge

Overview

Device Management (DM) Bridge allows developers to locally configure and monitor IoT devices. This project exposes APIs for UWP, and non-UWP applications to easily perform device management. UWP applications can use WinRT APIs, and non-UWP applications can directly call the Rpc API.

Architecture

DM Bridge is split into 3 main projects:

  • DMBridgeInterface defines the Rpc methods that DMBridge will implement, and that DMBridgeComponent will call.
  • DMBridge is an NTService that runs as the SYSTEM account and runs an Rpc server, exposing the APIs defined in DMBridgeInterface.
  • DMBridgeComponenet is a WinRT/C++ Component, and what can be built as a NuGet package. It provides projections for the Rpc API that DMBridge serves. This allows any UWP application to easily consume the API (UWP Example). Non-UWP applications can directly call the Rpc API exposed by DMBridge rather than going through this UWP-specific project (Non-UWP Example).

The below diagram illustrates how each project in this solution is involved for a UWP application.

architecture diagram

Getting Started

Dev Machine Setup

  • Visual Studio 15.9.6
  • Windows SDK 10.0.17134.0

DMBridge Executable

If an application calls a DM Bridge API while DMBridge.exe is not running, a COMException with the message the rpc server is unavailable will be thrown. Ensure DMBridge.exe is either installed and running as a service, or is running as Administrator using DMBridge.exe -console for testing purposes. For further documentation on how to use DMBridge.exe see the deploying DMBridge documentation.

UWP

The below is an example of how to use DMBridgeComponenet in a UWP C# application:

using DMBridgeComponent;

...

using (var serviceManager = new NTServiceBridge())
{
    int dhcpStatus = serviceManager.Query("dhcp");
}

For a more complete usage, including exception handling, see the included sample, or the UWP API documentation.

Non-UWP

Non-UWP applications can directly call the Rpc methods that DMBridge serves. Below is a simple example of a c program using the DMBridgeRpcInterface project to call a DM Bridge API. The example below should:

  • Link with Rpcrt4.lib.
  • Reference DMBridgeRpcInterface or add the project to to the Includes Directory project variable.
  • Add DMBridgeInterface_c.c, which is generated by the DMBridgeRpcInterface project.
#include "DMBridgeInterface_h.h"
#include <stdio.h>
#include <Rpc.h>

#define RPC_PROTOCOL_SEQUENCE L"ncalrpc"
#define RPC_ENDPOINT L"DmBridgeRpcEndpoint"

int wmain(int argc, wchar_t *argv[])
{
    /* Create the Rpc handle */
    RPC_WSTR stringBinding = nullptr;
    RPC_BINDING_HANDLE rpcHandle = nullptr;

    RpcStringBindingCompose(
                NULL,
                (RPC_WSTR)RPC_PROTOCOL_SEQUENCE,
                NULL,
                (RPC_WSTR)RPC_ENDPOINT,
                NULL,
                &stringBinding);
    RpcBindingFromStringBinding(stringBinding, &rpcHandle);
    RpcStringFree(&stringBinding);

    /* Call a DM Bridge API */
    int dhcpStatus;
    wchar_t* dhcpServiceName = const_cast<wchar_t*>(L"dhcp");
    HRESULT ret = ::QueryServiceRpc(rpcHandle, dhcpServiceName, &dhcpStatus);

    if (ret == S_OK)
    {
        // There were no errors
        printf("DHCP service status: %d", dhcpStatus);
    }

    /* Close the Rpc handle */
    RpcBindingFree(&rpcHandle);

    return 0;
}

/* These must be included for Rpc */
/******************************************************/
/*         MIDL allocate and free                     */
/******************************************************/
void __RPC_FAR * __RPC_USER midl_user_allocate(size_t len)
{
    return(malloc(len));
}

void __RPC_USER midl_user_free(void __RPC_FAR * ptr)
{
    free(ptr);
}

For a more complete usage, including exception handling, see DMBridgeComponent.

Other Documentation

Open-Source Libraries

DM Bridge uses the following open-source libraries:

  • jsoncpp: A C++ JSON parser under either the MIT License or Public Domain.

device-management-bridge's People

Contributors

gmileka avatar schmittjoseph avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.