working on it ...

Filters

Explore Public Snippets

Sort by

Found 355 snippets matching: rpc

    public by tomsim modified Jan 21, 2018  1399  1  6  0

    Simple RPC call

    Simple function to call RPC (only 1k uncompressed). Use this instead of JQuery. Alternatively, use zepto.min.js from zeptojs.com if you have 26K to spare.
    /* 
    Addapted from Paolo Manna git pmanna/mongoose_os_playground browser_rpc_service.js
    */
    
    var platform = '';
    var host = '';
    
    var defCallBack = function(response) {
      if ((response) && (response.error)) {
    	  alert(response.message);
      }
    };
    
    // Common call to RPC services on the board
    function callRPCService(cmd, params, callback) {
      if (!callback) {
    	  callback = defCallBack;
      }
      var xhttp = new XMLHttpRequest();
      
      xhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
          callback(this.response);
        }
      };
      
      xhttp.open('POST', 'rpc/' + cmd + '?' + new Date().getTime(), true);
      xhttp.responseType = 'json';
      xhttp.send(JSON.stringify(params));
    }
    
    // Discover which platform we're using, to enable/disable features
    function startup() {
      callRPCService('Config.Get',{}, function(response) {
        if (response) {
          platform = response.device.id;
          console.log('Platform is: ' + platform);
    
          var mac_id = (response.device.id.split("_"))[1];
    
          host = mac_id + '.local';
          document.getElementById("hostname").innerHTML = host;
        }
      });
    }
    
    // Reboots the microcontroller
    function rebootDevice() {
      callRPCService('Sys.Reboot',{delay_ms:500});
    }
    
    						

    public by tomsim modified Jan 21, 2018  1390  1  5  0

    Using simple RPC service

    Use simple rpc script to call RPC service on small IOT devices
    <html>
    <head>
    	<script src="simple_rpc_service.js"></script>
    </head>
    <body onLoad='startup();'>
    <h4 id="hostname"> </h4>
    <p>Hello, see <a target="_blank" href="/rpc/Config.Get">rpc</a>
    <br><a target="_blank" href="/rpc/clearAll">clear strip</a>
    
    <p><table>
      <tr><td>Pin</td> <td><input type="number" id="GPIO.pin" value='2'/></td></tr>
      <tr><td>Red</td><td><input type="range" id="rval" name="rval" min="0" max="255" value='0' onchange="setPixel()"/></td></tr>
      <tr><td>Green</td><td><input type="range" id="gval" name="gval" min="0" max="255" value='0' onchange="setPixel()"/></td></tr>
      <tr><td>Blue</td><td><input type="range" id="bval" name="bval" min="0" max="255" value='0' onchange="setPixel()"/></td></tr>
    </table>
    <p><button href="#" id="setPixel" onclick="setPixel()">Set Pixel</button>
    <button href="#" id="clearAll" onclick="callRPCService('clearAll')">Clear All Pixel</button>
    <p><button href="#" id="setPixel" onclick="rebootDevice()">Reboot</button>
    
    <script>
    
      var log = function(msg) {
        console.log(msg);
      };
      log('Starting ...');
      function setPixel() {
        log("setPixel...");
      	var pin = parseInt(document.getElementById("GPIO.pin").value);
      	var rv = parseInt(document.getElementById("rval").value);
      	var gv = parseInt(document.getElementById("gval").value);
      	var bv = parseInt(document.getElementById("bval").value);
    	callRPCService('setPixel',{px:pin, r:rv, g:gv, b:bv});
      };
    </script>
    
    </body>
    </html>
    

    public by msdn modified Jan 12, 2015  465  0  5  0

    GetParentPoolArrayFromPoolIds: Returns an string array of reference paths for each specified pool ID.

    Returns an string array of reference paths for each specified pool ID. The ManagementScope to use to connect to WMI. The Resource Pool Configuration Service MOB. The resource type to assign. The resource subtype to assign. An ArrayList of pool IDs. resources. An array of reference paths for Msvm_ResourcePool objects.
    /// <summary>
    /// Returns an string array of reference paths for each specified pool ID.
    /// </summary>
    /// <param name="scope">The ManagementScope to use to connect to WMI.</param>
    /// <param name="rPConfigurationService">The Resource Pool
    /// Configuration Service MOB.</param>
    /// <param name="resourceType">The resource type to assign.</param>
    /// <param name="resourceSubType">The resource subtype to assign.</param>
    /// <param name="poolIdArray">An ArrayList of pool IDs.</param>
    /// resources.</param>
    /// <returns>An array of reference paths for Msvm_ResourcePool objects.</returns>
    internal static string[]
    GetParentPoolArrayFromPoolIds(
        ManagementScope scope,
        string resourceType,
        string resourceSubType,
        string[] poolIdArray)
    {
        List<string> pathList = new List<string>();
    
        foreach (string poolId in poolIdArray)
        {
            pathList.Add(
                MsvmResourcePool.GetResourcePoolPath(
                    scope,
                    resourceType,
                    resourceSubType,
                    poolId));
        }
    
        return pathList.ToArray();
    }

    public by msdn modified Jan 12, 2015  297  0  5  0

    ModifyPoolResourcesHelper: Modifies the host resources assigned to a resource pool.

    Modifies the host resources assigned to a resource pool. The ManagementScope to use to connect to WMI. service management object. The resource pool configuration The resource type to assign. The resource subtype to assign. The pool ID of a resource pool. An array of strings that specify the parent pool IDs. An array of string arrays th
    /// <summary>
    /// Modifies the host resources assigned to a resource pool.
    /// </summary>
    /// <param name="scope">The ManagementScope to use to connect to WMI.</param>
    /// service management object.</param>
    /// <param name="rPConfigurationService">The resource pool configuration</param>
    /// <param name="resourceType">The resource type to assign.</param>
    /// <param name="resourceSubType">The resource subtype to assign.</param>
    /// <param name="poolId">The pool ID of a resource pool.</param>
    /// <param name="parentPoolIdArray">An array of strings that specify the parent
    /// pool IDs.</param>
    /// <param name="poolName">An array of string arrays that represent the host
    /// resources</param>
    internal static void
    ModifyPoolResourcesHelper(
        ManagementScope scope,
        ManagementObject rPConfigurationService,
        string resourceType,
        string resourceSubType,
        string poolId,
        string[] parentPoolIdArray,
        string[][] parentHostResourcesArray)
    {
        string poolPath =
            MsvmResourcePool.GetResourcePoolPath(
                    scope,
                    resourceType,
                    resourceSubType,
                    poolId);
    
        ModifyPoolResourcesByPath(
            scope,
            rPConfigurationService,
            resourceType,
            resourceSubType,
            poolPath,
            parentPoolIdArray,
            parentHostResourcesArray);
    }

    public by msdn modified Jan 12, 2015  268  0  5  0

    ModifyPoolResourcesByPath: Modifies the host resources assigned to a resource pool.

    Modifies the host resources assigned to a resource pool. The ManagementScope to use to connect to WMI. service management object. The resource pool configuration The resource type to assign. The resource subtype to assign. The reference path to a resource pool. An array of strings that specify the parent pool IDs. An array of string ar
    /// <summary>
    /// Modifies the host resources assigned to a resource pool.
    /// </summary>
    /// <param name="scope">The ManagementScope to use to connect to WMI.</param>
    /// service management object.</param>
    /// <param name="rPConfigurationService">The resource pool configuration</param>
    /// <param name="resourceType">The resource type to assign.</param>
    /// <param name="resourceSubType">The resource subtype to assign.</param>
    /// <param name="poolPath">The reference path to a resource pool.</param>
    /// <param name="parentPoolIdArray">An array of strings that specify the parent
    /// pool IDs.</param>
    /// <param name="poolName">An array of string arrays that represent the host
    /// resources</param>
    internal static void
    ModifyPoolResourcesByPath(
        ManagementScope scope,
        ManagementObject rPConfigurationService,
        string resourceType,
        string resourceSubType,
        string poolPath,
        string[] parentPoolIdArray,
        string[][] parentHostResourcesArray)
    {
        if (parentPoolIdArray.Length == 0)
        {
            throw new ManagementException(string.Format(
                CultureInfo.CurrentCulture,
                "At least one parent pool must be specified when modifying a ",
                "resource pool's host resources (poolPath \"{0}\")", poolPath));
        }
    
        if (parentPoolIdArray.Length != parentHostResourcesArray.Length)
        {
            throw new ManagementException(string.Format(
                CultureInfo.CurrentCulture,
                "When modifying a child resource pool's host resources,  a host ",
                "resource must be specified for each parent pool. Shared allocations",
                "are not supported (poolPath \"{0}\")",
                poolPath));
        }
    
        string[] parentPoolPathArray =
            ResourcePoolUtilities.GetParentPoolArrayFromPoolIds(
                scope,
                resourceType,
                resourceSubType,
                parentPoolIdArray);
    
        string[] resourceAllocationSettingDataArray =
            MsvmResourceAllocationSettingData.GetNewPoolAllocationSettingsArray(
                scope,
                resourceType,
                resourceSubType,
                parentPoolIdArray,
                parentHostResourcesArray);
    
        using (ManagementBaseObject inParams =
               rPConfigurationService.GetMethodParameters(
                   "ModifyPoolResources"))
        {
            inParams["ChildPool"] = poolPath;
            inParams["ParentPools"] = parentPoolPathArray;
            inParams["AllocationSettings"] = resourceAllocationSettingDataArray;
    
            using (ManagementBaseObject outParams =
                   rPConfigurationService.InvokeMethod(
                       "ModifyPoolResources",
                       inParams,
                       null))
            {
                WmiUtilities.ValidateOutput(outParams, scope, true, true);
            }
        }
    }

    public by msdn modified Jan 12, 2015  252  0  5  0

    DeletePoolHelper: Delete a resource pool.

    Delete a resource pool. The ManagementScope to use to connect to WMI. service management object. The resource pool configuration. The resource type to assign. The resource subtype to assign. The pool ID to assign.
    /// <summary>
    /// Delete a resource pool.
    /// </summary>
    /// <param name="scope">The ManagementScope to use to connect to WMI.</param>
    /// service management object.</param>
    /// <param name="rPConfigurationService">The resource pool configuration.</param>
    /// <param name="resourceType">The resource type to assign.</param>
    /// <param name="resourceSubType">The resource subtype to assign.</param>
    /// <param name="poolId">The pool ID to assign.</param>
    internal static void
    DeletePoolHelper(
        ManagementScope scope,
        ManagementObject rPConfigurationService,
        string resourceType,
        string resourceSubType,
        string poolId)
    {
        string poolPath =
            MsvmResourcePool.GetResourcePoolPath(
                    scope,
                    resourceType,
                    resourceSubType,
                    poolId);
    
        using (ManagementBaseObject inParams =
              rPConfigurationService.GetMethodParameters(
                  "DeletePool"))
        {
            inParams["Pool"] = poolPath;
    
            using (ManagementBaseObject outParams =
                   rPConfigurationService.InvokeMethod(
                       "DeletePool",
                       inParams,
                       null))
            {
                WmiUtilities.ValidateOutput(outParams, scope, true, true);
            }
        }
    }

    public by msdn modified Jan 12, 2015  231  0  5  0

    ModifyPoolSettingsByPath: Modifies the resource pool's settings.

    Modifies the resource pool's settings. The ManagementScope to use to connect to WMI. service management object. The resource pool configuration The reference path to a resource pool. An embedded instance string of a Msvm_ResourcePoolSettingData object. A Msvm_ResourcePool object.
    /// <summary>
    /// Modifies the resource pool's settings.
    /// </summary>
    /// <param name="scope">The ManagementScope to use to connect to WMI.</param>
    /// service management object.</param>
    /// <param name="rPConfigurationService">The resource pool configuration
    /// <param name="poolPath">The reference path to a resource pool.</param>
    /// <param name="resourcePoolSettingData">An embedded instance string of a
    /// Msvm_ResourcePoolSettingData object.</param>
    /// <returns>A Msvm_ResourcePool object.</returns>
    internal static void
    ModifyPoolSettingsByPath(
        ManagementScope scope,
        ManagementObject rPConfigurationService,
        string poolPath,
        string resourcePoolSettingData)
    {
        using (ManagementBaseObject inParams =
               rPConfigurationService.GetMethodParameters(
                   "ModifyPoolSettings"))
        {
            inParams["ChildPool"] = poolPath;
            inParams["PoolSettings"] = resourcePoolSettingData;
    
            using (ManagementBaseObject outParams =
                   rPConfigurationService.InvokeMethod(
                       "ModifyPoolSettings",
                       inParams,
                       null))
            {
                WmiUtilities.ValidateOutput(outParams, scope, true, true);
            }
        }
    }

    public by msdn modified Jan 12, 2015  227  0  5  0

    CreatePoolHelper: Creates a resource pool and returns its associated CIM_ResourcePool MOB.

    Creates a resource pool and returns its associated CIM_ResourcePool MOB. The ManagementScope to use to connect to WMI. service management object. The resource pool configuration. The resource type to assign. The resource subtype to assign. The pool ID to assign. The pool name to assign. An array of strings that specify the parent pool
    /// <summary>
    /// Creates a resource pool and returns its associated CIM_ResourcePool MOB.
    /// </summary>
    /// <param name="scope">The ManagementScope to use to connect to WMI.</param>
    /// service management object.</param>
    /// <param name="rPConfigurationService">The resource pool configuration.</param>
    /// <param name="resourceType">The resource type to assign.</param>
    /// <param name="resourceSubType">The resource subtype to assign.</param>
    /// <param name="childPoolId">The pool ID to assign.</param>
    /// <param name="childPoolName">The pool name to assign.</param>
    /// <param name="parentPoolIdArray">An array of strings that specify the parent
    /// pool IDs.</param>
    /// <param name="poolName">An array of string arrays that represent the host
    /// resources.</param>
    /// <returns>A Msvm_ResourcePool object.</returns>
    internal static ManagementObject
    CreatePoolHelper(
        ManagementScope scope,
        ManagementObject rPConfigurationService,
        string resourceType,
        string resourceSubType,
        string childPoolId,
        string childPoolName,
        string[] parentPoolIdArray,
        string[][] parentHostResourcesArray)
    {
        if (parentPoolIdArray.Length == 0)
        {
            throw new ManagementException(string.Format(
                CultureInfo.CurrentCulture,
                "At least one parent pool must be specified when creating a ",
                "child resource pool (PoolId \"{0}\")", childPoolId));
        }
    
        if (parentPoolIdArray.Length != parentHostResourcesArray.Length)
        {
            throw new ManagementException(string.Format(
                CultureInfo.CurrentCulture,
                "When creating a child resource pool,  a host resource must be ",
                "specified for each parent pool. Shared allocations are not ",
                "supported (PoolId \"{0}\")", childPoolId));
        }
    
        string resourcePoolSettingData =
            MsvmResourcePoolSettingData.GetSettingsForPool(
                scope,
                resourceType,
                resourceSubType,
                childPoolId,
                childPoolName);
    
        string[] parentPoolPathArray =
            ResourcePoolUtilities.GetParentPoolArrayFromPoolIds(
                scope,
                resourceType,
                resourceSubType,
                parentPoolIdArray);
    
        string[] resourceAllocationSettingDataArray =
            MsvmResourceAllocationSettingData.GetNewPoolAllocationSettingsArray(
                scope,
                resourceType,
                resourceSubType,
                parentPoolIdArray,
                parentHostResourcesArray);
    
        using (ManagementBaseObject inParams =
               rPConfigurationService.GetMethodParameters(
                   "CreatePool"))
        {
            inParams["PoolSettings"] = resourcePoolSettingData;
            inParams["ParentPools"] = parentPoolPathArray;
            inParams["AllocationSettings"] = resourceAllocationSettingDataArray;
    
            using (ManagementBaseObject outParams =
                   rPConfigurationService.InvokeMethod(
                       "CreatePool",
                       inParams,
                       null))
            {
                if (WmiUtilities.ValidateOutput(outParams, scope, true, true))
                {
                    string poolPath = outParams["Pool"].ToString();
    
                    return new ManagementObject(
                        scope,
                        new ManagementPath(poolPath),
                        null);
                }
                else
                {
                    return null;
                }
            }
        }
    }

    public by msdn modified Jan 12, 2015  200  0  4  0

    ModifyPoolSettingsHelper: Modifies the resource pool's settings.

    Modifies the resource pool's settings. The ManagementScope to use to connect to WMI. service management object. The resource pool configuration The resource type to assign. The resource subtype to assign. The pool ID of a resource pool. An embedded instance string of a Msvm_ResourcePoolSettingData object. A Msvm_ResourcePool object.
    /// <summary>
    /// Modifies the resource pool's settings.
    /// </summary>
    /// <param name="scope">The ManagementScope to use to connect to WMI.</param>
    /// service management object.</param>
    /// <param name="rPConfigurationService">The resource pool configuration</param>
    /// <param name="resourceType">The resource type to assign.</param>
    /// <param name="resourceSubType">The resource subtype to assign.</param>
    /// <param name="poolId">The pool ID of a resource pool.</param>
    /// <param name="resourcePoolSettingData">An embedded instance string of a
    /// Msvm_ResourcePoolSettingData object.</param>
    /// <returns>A Msvm_ResourcePool object.</returns>
    internal static void
    ModifyPoolSettingsHelper(
        ManagementScope scope,
        ManagementObject rPConfigurationService,
        string resourceType,
        string resourceSubType,
        string poolId,
        string resourcePoolSettingData)
    {
        string poolPath =
            MsvmResourcePool.GetResourcePoolPath(
                    scope,
                    resourceType,
                    resourceSubType,
                    poolId);
    
        ModifyPoolSettingsByPath(
            scope,
            rPConfigurationService,
            poolPath,
            resourcePoolSettingData);
    }

    public by msdn modified Jan 12, 2015  191  0  4  0

    GetNewPoolAllocationSettingsArray: Returns a string array of embedded instance strings of Msvm_ResourceAllocationSettingData objects for each specified pool ID.

    Returns a string array of embedded instance strings of Msvm_ResourceAllocationSettingData objects for each specified pool ID. The ManagementScope to use to connect to WMI. The Resource Pool Configuration Service MOB. The resource type to assign. The resource subtype to assign. A string array of pool IDs. An array of string arrays that s
    /// <summary>
    /// Returns a string array of embedded instance strings of Msvm_ResourceAllocationSettingData
    /// objects for each specified pool ID.
    /// </summary>
    /// <param name="scope">The ManagementScope to use to connect to WMI.</param>
    /// <param name="rPConfigurationService">The Resource Pool
    /// Configuration Service MOB.</param>
    /// <param name="resourceType">The resource type to assign.</param>
    /// <param name="resourceSubType">The resource subtype to assign.</param>
    /// <param name="poolIdArray">A string array of pool IDs.</param>
    /// <param name="hostResourcesArray">An array of string arrays that specify host
    /// resources.</param>
    /// <returns>An array of embedded instance strings of
    /// Msvm_ResourceAllocationSettingData objects.</returns>
    internal static string[]
    GetNewPoolAllocationSettingsArray(
        ManagementScope scope,
        string resourceType,
        string resourceSubType,
        string[] poolIdArray,
        string[][] hostResourcesArray)
    {
        List<string> rasdList = new List<string>();
    
        for (uint index = 0; index < poolIdArray.Length; ++index)
        {
            rasdList.Add(GetNewPoolAllocationSettings(
                scope,
                resourceType,
                resourceSubType,
                poolIdArray[index],
                hostResourcesArray[index]));
        }
    
        return rasdList.ToArray();
    }
    • Public Snippets
    • Channels Snippets