Merge pull request #9 from Azure/erichb-develop
Convert to using NuGet packages and removing all static dependencies on Gateway SDK
This commit is contained in:
Коммит
0e315f5de4
13
Module.cs
13
Module.cs
|
@ -67,11 +67,8 @@ namespace Opc.Ua.Client
|
|||
// check the application certificate.
|
||||
await application.CheckApplicationInstanceCertificate(false, 0);
|
||||
|
||||
if (m_configuration.SecurityConfiguration.AutoAcceptUntrustedCertificates)
|
||||
{
|
||||
m_configuration.CertificateValidator.CertificateValidation += new CertificateValidationEventHandler(CertificateValidator_CertificateValidation);
|
||||
}
|
||||
|
||||
m_configuration.CertificateValidator.CertificateValidation += new CertificateValidationEventHandler(CertificateValidator_CertificateValidation);
|
||||
|
||||
// get a list of persisted endpoint URLs and create a session for each.
|
||||
List<Uri> endpointUrls = new List<Uri>();
|
||||
PublishedNodesCollection nodesLookups = PublishedNodesCollection.Load(m_configuration);
|
||||
|
@ -115,12 +112,12 @@ namespace Opc.Ua.Client
|
|||
false,
|
||||
m_configuration.ApplicationName,
|
||||
60000,
|
||||
null,
|
||||
new UserIdentity(new AnonymousIdentityToken()),
|
||||
null);
|
||||
|
||||
if (newSession != null)
|
||||
{
|
||||
Console.WriteLine("Opc.Ua.Client.SampleModule: Created session with updated endpoint " + selectedEndpoint.EndpointUrl + " from server!");
|
||||
Console.WriteLine("Opc.Ua.Client.SampleModule: Created session with updated endpoint " + configuredEndpoint.EndpointUrl + " from server!");
|
||||
newSession.KeepAlive += new KeepAliveEventHandler(StandardClient_KeepAlive);
|
||||
m_sessions.Add(newSession);
|
||||
}
|
||||
|
@ -162,7 +159,7 @@ namespace Opc.Ua.Client
|
|||
Session matchingSession = null;
|
||||
foreach(Session session in m_sessions)
|
||||
{
|
||||
if (session.Endpoint.EndpointUrl == Utils.ReplaceLocalhost(nodeLookup.EndPointURL.ToString()))
|
||||
if (session.Endpoint.EndpointUrl.ToLowerInvariant().TrimEnd('/') == Utils.ReplaceLocalhost(nodeLookup.EndPointURL.ToString()).ToLowerInvariant().TrimEnd('/'))
|
||||
{
|
||||
matchingSession = session;
|
||||
break;
|
||||
|
|
|
@ -30,14 +30,32 @@
|
|||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x86\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
|
||||
<OutputPath>bin\x86\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="BouncyCastle.Crypto, Version=1.8.1.0, Culture=neutral, PublicKeyToken=0e99375e54769942, processorArchitecture=MSIL">
|
||||
<HintPath>packages\Portable.BouncyCastle.1.8.1.2\lib\net4\BouncyCastle.Crypto.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Azure.IoT.Gateway, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>binding\Microsoft.Azure.IoT.Gateway.dll</HintPath>
|
||||
<HintPath>packages\Azure.IoT.Gateway.SDK.Net.2017.1.13.2\lib\net40\Microsoft.Azure.IoT.Gateway.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
|
@ -45,15 +63,15 @@
|
|||
</Reference>
|
||||
<Reference Include="Opc.Ua.Client, Version=1.3.340.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>packages\OPCFoundation.NetStandard.Opc.Ua.SDK.0.1.0\lib\net46\Opc.Ua.Client.dll</HintPath>
|
||||
<HintPath>packages\OPCFoundation.NetStandard.Opc.Ua.SDK.0.1.1\lib\net46\Opc.Ua.Client.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Opc.Ua.Configuration, Version=1.3.340.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>packages\OPCFoundation.NetStandard.Opc.Ua.SDK.0.1.0\lib\net46\Opc.Ua.Configuration.dll</HintPath>
|
||||
<HintPath>packages\OPCFoundation.NetStandard.Opc.Ua.SDK.0.1.1\lib\net46\Opc.Ua.Configuration.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Opc.Ua.Core, Version=1.3.340.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>packages\OPCFoundation.NetStandard.Opc.Ua.Core.0.1.0\lib\net46\Opc.Ua.Core.dll</HintPath>
|
||||
<HintPath>packages\OPCFoundation.NetStandard.Opc.Ua.Core.0.1.1\lib\net46\Opc.Ua.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
|
@ -70,9 +88,19 @@
|
|||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
<Content Include="gateway_config.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<None Include="packages.config">
|
||||
<SubType>Designer</SubType>
|
||||
</None>
|
||||
<None Include="README.md" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Opc.Ua.Client.SampleModule.Config.xml">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
|
|
@ -6,21 +6,24 @@ MinimumVisualStudioVersion = 10.0.40219.1
|
|||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Opc.Ua.Client.Module", "Opc.Ua.Client.Module.csproj", "{25D19FFD-D553-4270-8A7A-6F510572BDC0}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dotnet_binding_sample", "binding\dotnet_binding_sample.vcxproj", "{7064A025-384F-3689-89FD-9E480DBFE5C9}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{25D19FFD-D553-4270-8A7A-6F510572BDC0} = {25D19FFD-D553-4270-8A7A-6F510572BDC0}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{25D19FFD-D553-4270-8A7A-6F510572BDC0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{25D19FFD-D553-4270-8A7A-6F510572BDC0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{25D19FFD-D553-4270-8A7A-6F510572BDC0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{25D19FFD-D553-4270-8A7A-6F510572BDC0}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{7064A025-384F-3689-89FD-9E480DBFE5C9}.Debug|Any CPU.ActiveCfg = Debug|Win32
|
||||
{7064A025-384F-3689-89FD-9E480DBFE5C9}.Debug|Any CPU.Build.0 = Debug|Win32
|
||||
{7064A025-384F-3689-89FD-9E480DBFE5C9}.Release|Any CPU.ActiveCfg = Release|Win32
|
||||
{7064A025-384F-3689-89FD-9E480DBFE5C9}.Release|Any CPU.Build.0 = Release|Win32
|
||||
{25D19FFD-D553-4270-8A7A-6F510572BDC0}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{25D19FFD-D553-4270-8A7A-6F510572BDC0}.Debug|x86.Build.0 = Debug|x86
|
||||
{25D19FFD-D553-4270-8A7A-6F510572BDC0}.Release|x86.ActiveCfg = Release|x86
|
||||
{25D19FFD-D553-4270-8A7A-6F510572BDC0}.Release|x86.Build.0 = Release|x86
|
||||
{7064A025-384F-3689-89FD-9E480DBFE5C9}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{7064A025-384F-3689-89FD-9E480DBFE5C9}.Debug|x86.Build.0 = Debug|Win32
|
||||
{7064A025-384F-3689-89FD-9E480DBFE5C9}.Release|x86.ActiveCfg = Release|Win32
|
||||
{7064A025-384F-3689-89FD-9E480DBFE5C9}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
37
README.md
37
README.md
|
@ -1,9 +1,9 @@
|
|||
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments
|
||||
|
||||
# OPC UA Client Module for the Azure IoT Gateway SDK release 2016-11-18
|
||||
This reference implementation demonstrates how the Azure IoT Gateway SDK can be used to connect to existing OPC UA servers and send JSON encoded telemetry data from these servers via the soon to be released OPC UA "Pub/Sub" specification extension (part 14, currently in draft state) to Azure IoT Hub. All transports to Azure that the Gateway SDK supports can be used, i.e. HTTPS, AMQP and MQTT. The transport is selected in the Transport setting in gateway_config.JSON.
|
||||
# OPC UA Client Module for the Azure IoT Gateway SDK
|
||||
This reference implementation demonstrates how the Azure IoT Gateway SDK can be used to connect to existing OPC UA servers and send JSON encoded telemetry data from these servers in OPC UA "Pub/Sub" format (using a JSON payload) to Azure IoT Hub. All transport protocols supported by the Gateway SDK can be used, i.e. HTTPS, AMQP and MQTT. The transport is selected in the transport setting in gateway_config.JSON.
|
||||
|
||||
Visit https://github.com/OPCFoundation/UA-.NETStandardLibrary for the sources to the NuGet packages used in this implementation.
|
||||
Visit http://opcfoundation.github.io/UA-.NETStandardLibrary/ for OPC UA documentation.
|
||||
|
||||
## Operating System Compatibility
|
||||
Since this reference implementation is written for .NET, Windows 7, 8, 8.1 & 10 are supported right now. Once the Gateway SDK supports .NET Standard, so will this module and then Linux will also be supported.
|
||||
|
@ -11,29 +11,20 @@ Since this reference implementation is written for .NET, Windows 7, 8, 8.1 & 10
|
|||
## Directory Structure
|
||||
|
||||
### /binding
|
||||
This folder contains the binding to the Gateway SDK, i.e. the native entry point required (main.c), the gateway configuration file (gateway_config.json) as well as the two OPC UA gateway module configuration files (Opc.Ua.Client.SampleModule.Config.xml and Opc.Ua.Client.SampleModule.Endpoints.xml).
|
||||
|
||||
## /inc
|
||||
This folder contains the headers required for the dotnet binding project, copied from the Azure IoT SDK for convenience. **These should be replaced with the newest ones from the gateway SDK!**
|
||||
|
||||
### /lib
|
||||
This folder contains the static libraries the native entry point needs to link with.
|
||||
This folder contains the native entry point required for the Gateway SDK (main.c).
|
||||
|
||||
### Root Directory
|
||||
This folder contains the C# OPC UA module source file (Module.cs) and the NuGet package configuration file (packages.config).
|
||||
This folder contains the C# OPC UA module source file (Module.cs), the gateway configuration file (gateway_config.json) and the OPC UA gateway module configuration file (Opc.Ua.Client.SampleModule.Config.xml).
|
||||
|
||||
## Configuring the Sample Module
|
||||
The OPC UA server endpoints the module should connect to as well as the list of OPC UA nodes for each endpoint that should be published to Azure IoT Hub can be configured in the **ListOfPublishedNodes** section of the **Opc.Ua.Client.SampleModule.Config.xml** configuration file. The **Current Server Time** node (node ID 2258) is specified as an example.
|
||||
## Configuring the Module
|
||||
The OPC UA server endpoints the module should connect to and the list of OPC UA nodes for each endpoint that should be published to Azure IoT Hub can be configured in the **ListOfPublishedNodes** section of the **Opc.Ua.Client.SampleModule.Config.xml** configuration file. The **Current Server Time** node (node ID 2258) is specified as an example.
|
||||
|
||||
Also, in the gateway_config.json, configure the name of IoT Hub you want to send the telemetry to (JSON field "IoTHubName") as well as the IoT Hub device ID and shared access key to use (JSON field "args").
|
||||
Also, in the gateway_config.json, configure the name of IoT Hub you want to send the telemetry to (JSON field "IoTHubName") and the IoT Hub device ID and shared access key to use (JSON field "args").
|
||||
|
||||
## Building and Running the Sample Module
|
||||
To build the reference implementation, you first need to clone and build the Azure IoT Gateway SDK. See https://github.com/azure/azure-iot-gateway-sdk for more information and **follow the instructions for building the gateway with the "dotnet binding", i.e. running tools\build_dotnet.cmd followed by tools\build.cmd --enable-dotnet-binding**
|
||||
## Building and Running the Module
|
||||
Simply open the solution file in Visual Studio and build it. Make sure you specify the gateway_config.json as a command line parameter, set the debugger type to Mixed and set the working directory to $(OutDir) before debugging.
|
||||
|
||||
Once done, copy the just compiled **aziotsharedutil.lib** & .pdb, **gateway.lib** & .pdb, **nanomsg.lib** & .pdb and **parson.lib** & .pdb to the **/lib** folder. It is easiest just to search for them. If you find multiple copies, any of them will do.
|
||||
|
||||
Then copy the just compiled **dotnet.dll** & .pdb, **iothub.dll** & .pdb, **Microsoft.Azure.IoT.Gateway.dll** & .pdb and **nanomsg.dll** & .pdb to the **/binding** folder. Again, just to search for them and if you find multiple copies, any of them will do).
|
||||
|
||||
Then open the solution file (**Opc.Ua.Client.Module.sln**) in Visual Studio and rebuild the solution. This will first restore the NuGet packages and then build both the binding project and the module project.
|
||||
|
||||
Then run the binding sample in the debugger. Enjoy!
|
||||
## Updating NuGet Packages
|
||||
There are manual steps required after updating the OPC UA or Gateway SDK NuGet packages:
|
||||
1. When updating the OPC UA NuGet packages, you need to re-add the new reference to the updated OPC UA DLLs in the Opc.Ua.Client.Module project as Visual Studio doesn't do that automatically for .Net Standard assemblies in .Net Framework projects.
|
||||
2. When updating the Gateway SDK NuGet package, you need to update the path in the post-build copy command for the Gateway SDK DLLs in the dotnet_binding_sample project.
|
||||
|
|
|
@ -39,13 +39,13 @@
|
|||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup>
|
||||
<_ProjectFileVersion>10.0.20506.1</_ProjectFileVersion>
|
||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\bin\Debug\</OutDir>
|
||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\bin\x86\Debug\</OutDir>
|
||||
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">dotnet_binding_sample.dir\Debug\</IntDir>
|
||||
<TargetName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">dotnet_binding_sample</TargetName>
|
||||
<TargetExt Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">.exe</TargetExt>
|
||||
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
|
||||
<GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</GenerateManifest>
|
||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\bin\Release\</OutDir>
|
||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\bin\x86\Release\</OutDir>
|
||||
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">dotnet_binding_sample.dir\Release\</IntDir>
|
||||
<TargetName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">dotnet_binding_sample</TargetName>
|
||||
<TargetExt Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">.exe</TargetExt>
|
||||
|
@ -63,7 +63,7 @@
|
|||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<AdditionalOptions> /guard:cf %(AdditionalOptions)</AdditionalOptions>
|
||||
<AdditionalIncludeDirectories>..\inc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AssemblerListingLocation>Debug/</AssemblerListingLocation>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<CompileAs>CompileAsC</CompileAs>
|
||||
|
@ -93,15 +93,11 @@
|
|||
<PostBuildEvent>
|
||||
<Message>
|
||||
</Message>
|
||||
<Command>copy $(ProjectDir)\*.json $(ProjectDir)$(OutDir)
|
||||
copy $(ProjectDir)\*.dll $(ProjectDir)$(OutDir)
|
||||
copy $(ProjectDir)\*.pdb $(ProjectDir)$(OutDir)
|
||||
copy $(ProjectDir)\*.xml $(ProjectDir)$(OutDir)
|
||||
</Command>
|
||||
<Command>copy $(ProjectDir)\..\packages\Azure.IoT.Gateway.SDK.Net.2017.1.13.2\build\x86\*.dll $(OutDir)</Command>
|
||||
</PostBuildEvent>
|
||||
<Link>
|
||||
<AdditionalOptions> /machine:X86 /guard:cf %(AdditionalOptions)</AdditionalOptions>
|
||||
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;comdlg32.lib;advapi32.lib;crypt32.lib;winhttp.lib;secur32.lib;ws2_32.lib;mswsock.lib;rpcrt4.lib;..\lib\gateway.lib;..\lib\aziotsharedutil.lib;..\lib\nanomsg.lib;..\lib\parson.lib</AdditionalDependencies>
|
||||
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;comdlg32.lib;advapi32.lib;crypt32.lib;winhttp.lib;secur32.lib;ws2_32.lib;mswsock.lib;rpcrt4.lib;</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<GenerateDebugInformation>Debug</GenerateDebugInformation>
|
||||
<IgnoreSpecificDefaultLibraries>%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
|
||||
|
@ -120,7 +116,7 @@ copy $(ProjectDir)\*.xml $(ProjectDir)$(OutDir)
|
|||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<AdditionalOptions> /guard:cf %(AdditionalOptions)</AdditionalOptions>
|
||||
<AdditionalIncludeDirectories>..\inc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AssemblerListingLocation>Release/</AssemblerListingLocation>
|
||||
<CompileAs>CompileAsC</CompileAs>
|
||||
<ExceptionHandling>
|
||||
|
@ -150,15 +146,11 @@ copy $(ProjectDir)\*.xml $(ProjectDir)$(OutDir)
|
|||
<PostBuildEvent>
|
||||
<Message>
|
||||
</Message>
|
||||
<Command>copy $(ProjectDir)\*.json $(ProjectDir)$(OutDir)
|
||||
copy $(ProjectDir)\*.dll $(ProjectDir)$(OutDir)
|
||||
copy $(ProjectDir)\*.pdb $(ProjectDir)$(OutDir)
|
||||
copy $(ProjectDir)\*.xml $(ProjectDir)$(OutDir)
|
||||
</Command>
|
||||
<Command>copy $(ProjectDir)\..\packages\Azure.IoT.Gateway.SDK.Net.2017.1.13.2\build\x86\*.dll $(OutDir)</Command>
|
||||
</PostBuildEvent>
|
||||
<Link>
|
||||
<AdditionalOptions> /machine:X86 /guard:cf %(AdditionalOptions)</AdditionalOptions>
|
||||
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;comdlg32.lib;advapi32.lib;crypt32.lib;winhttp.lib;secur32.lib;ws2_32.lib;mswsock.lib;rpcrt4.lib;..\lib\gateway.lib;..\lib\aziotsharedutil.lib;..\lib\nanomsg.lib;..\lib\parson.lib</AdditionalDependencies>
|
||||
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;comdlg32.lib;advapi32.lib;crypt32.lib;winhttp.lib;secur32.lib;ws2_32.lib;mswsock.lib;rpcrt4.lib</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<GenerateDebugInformation>No</GenerateDebugInformation>
|
||||
<IgnoreSpecificDefaultLibraries>%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
|
||||
|
@ -174,28 +166,6 @@ copy $(ProjectDir)\*.xml $(ProjectDir)$(OutDir)
|
|||
</Command>
|
||||
</CustomBuildStep>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Opc.Ua.Client.Module.csproj">
|
||||
<Project>{25d19ffd-d553-4270-8a7a-6f510572bdc0}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Resource Include="gateway_config.json">
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</DeploymentContent>
|
||||
<FileType>Document</FileType>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</DeploymentContent>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
</Resource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Xml Include="Opc.Ua.Client.SampleModule.Config.xml">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</DeploymentContent>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</DeploymentContent>
|
||||
</Xml>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.c" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -1,30 +1,53 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include "gateway.h"
|
||||
|
||||
typedef void* (__cdecl *P_GATEWAY_CREATE_FROM_JSON)(char*);
|
||||
typedef void (__cdecl *P_GATEWAY_DESTROY)(void*);
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
GATEWAY_HANDLE gateway;
|
||||
if (argc != 2)
|
||||
if (argc != 2)
|
||||
{
|
||||
printf("usage: dotnet_binding_sample configFile\n");
|
||||
printf("where configFile is the name of the file that contains the Gateway configuration\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
HINSTANCE hDLL = LoadLibraryA("gateway.dll");
|
||||
if (!hDLL)
|
||||
{
|
||||
printf("failed to load gateway.dll, error: %d\n", GetLastError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
P_GATEWAY_CREATE_FROM_JSON Gateway_CreateFromJson = (P_GATEWAY_CREATE_FROM_JSON) GetProcAddress(hDLL, "Gateway_CreateFromJson");
|
||||
if (!Gateway_CreateFromJson)
|
||||
{
|
||||
printf("failed to load function Gateway_CreateFromJson, error: %d\n", GetLastError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
void* pGateway = Gateway_CreateFromJson(argv[1]);
|
||||
if (!pGateway)
|
||||
{
|
||||
printf("usage: dotnet_binding_sample configFile\n");
|
||||
printf("where configFile is the name of the file that contains the Gateway configuration\n");
|
||||
printf("failed to create the gateway from JSON\n");
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((gateway = Gateway_CreateFromJson(argv[1])) == NULL)
|
||||
{
|
||||
printf("failed to create the gateway from JSON\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("gateway successfully created from JSON\n");
|
||||
printf("gateway will run until ENTER is pressed\n");
|
||||
(void)getchar();
|
||||
Gateway_Destroy(gateway);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
printf("gateway successfully created from JSON\n");
|
||||
printf("gateway will run until ENTER is pressed\n");
|
||||
getchar();
|
||||
|
||||
P_GATEWAY_DESTROY Gateway_Destroy = (P_GATEWAY_DESTROY) GetProcAddress(hDLL, "Gateway_Destroy");
|
||||
if (Gateway_Destroy)
|
||||
{
|
||||
Gateway_Destroy(pGateway);
|
||||
}
|
||||
|
||||
FreeLibrary(hDLL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
#ifndef BUFFER_H
|
||||
#define BUFFER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <cstddef>
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#include <stddef.h>
|
||||
#endif
|
||||
|
||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
||||
|
||||
typedef struct BUFFER_TAG* BUFFER_HANDLE;
|
||||
|
||||
MOCKABLE_FUNCTION(, BUFFER_HANDLE, BUFFER_new);
|
||||
MOCKABLE_FUNCTION(, BUFFER_HANDLE, BUFFER_create, const unsigned char*, source, size_t, size);
|
||||
MOCKABLE_FUNCTION(, void, BUFFER_delete, BUFFER_HANDLE, handle);
|
||||
MOCKABLE_FUNCTION(, int, BUFFER_pre_build, BUFFER_HANDLE, handle, size_t, size);
|
||||
MOCKABLE_FUNCTION(, int, BUFFER_build, BUFFER_HANDLE, handle, const unsigned char*, source, size_t, size);
|
||||
MOCKABLE_FUNCTION(, int, BUFFER_unbuild, BUFFER_HANDLE, handle);
|
||||
MOCKABLE_FUNCTION(, int, BUFFER_enlarge, BUFFER_HANDLE, handle, size_t, enlargeSize);
|
||||
MOCKABLE_FUNCTION(, int, BUFFER_content, BUFFER_HANDLE, handle, const unsigned char**, content);
|
||||
MOCKABLE_FUNCTION(, int, BUFFER_size, BUFFER_HANDLE, handle, size_t*, size);
|
||||
MOCKABLE_FUNCTION(, int, BUFFER_append, BUFFER_HANDLE, handle1, BUFFER_HANDLE, handle2);
|
||||
MOCKABLE_FUNCTION(, int, BUFFER_prepend, BUFFER_HANDLE, handle1, BUFFER_HANDLE, handle2);
|
||||
MOCKABLE_FUNCTION(, unsigned char*, BUFFER_u_char, BUFFER_HANDLE, handle);
|
||||
MOCKABLE_FUNCTION(, size_t, BUFFER_length, BUFFER_HANDLE, handle);
|
||||
MOCKABLE_FUNCTION(, BUFFER_HANDLE, BUFFER_clone, BUFFER_HANDLE, handle);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* BUFFER_H */
|
|
@ -1,45 +0,0 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
#ifndef CONSTBUFFER_H
|
||||
#define CONSTBUFFER_H
|
||||
|
||||
#include "azure_c_shared_utility/buffer_.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <cstddef>
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#include <stddef.h>
|
||||
#endif
|
||||
|
||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
||||
|
||||
/*this is the handle*/
|
||||
typedef struct CONSTBUFFER_HANDLE_DATA_TAG* CONSTBUFFER_HANDLE;
|
||||
|
||||
/*this is what is returned when the content of the buffer needs access*/
|
||||
typedef struct CONSTBUFFER_TAG
|
||||
{
|
||||
const unsigned char* buffer;
|
||||
size_t size;
|
||||
} CONSTBUFFER;
|
||||
|
||||
/*this creates a new constbuffer from a memory area*/
|
||||
MOCKABLE_FUNCTION(, CONSTBUFFER_HANDLE, CONSTBUFFER_Create, const unsigned char*, source, size_t, size);
|
||||
|
||||
/*this creates a new constbuffer from an existing BUFFER_HANDLE*/
|
||||
MOCKABLE_FUNCTION(, CONSTBUFFER_HANDLE, CONSTBUFFER_CreateFromBuffer, BUFFER_HANDLE, buffer);
|
||||
|
||||
MOCKABLE_FUNCTION(, CONSTBUFFER_HANDLE, CONSTBUFFER_Clone, CONSTBUFFER_HANDLE, constbufferHandle);
|
||||
|
||||
MOCKABLE_FUNCTION(, const CONSTBUFFER*, CONSTBUFFER_GetContent, CONSTBUFFER_HANDLE, constbufferHandle);
|
||||
|
||||
MOCKABLE_FUNCTION(, void, CONSTBUFFER_Destroy, CONSTBUFFER_HANDLE, constbufferHandle);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONSTBUFFER_H */
|
|
@ -1,132 +0,0 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
/** @file constmap.h
|
||||
* @brief ConstMap is a module that implements a read-only dictionary
|
||||
* of @c const char* keys to @c const char* values.
|
||||
*/
|
||||
|
||||
#ifndef CONSTMAP_H
|
||||
#define CONSTMAP_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <cstddef>
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#include <stddef.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include "azure_c_shared_utility/macro_utils.h"
|
||||
#include "azure_c_shared_utility/crt_abstractions.h"
|
||||
#include "azure_c_shared_utility/map.h"
|
||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
||||
|
||||
#define CONSTMAP_RESULT_VALUES \
|
||||
CONSTMAP_OK, \
|
||||
CONSTMAP_ERROR, \
|
||||
CONSTMAP_INVALIDARG, \
|
||||
CONSTMAP_KEYNOTFOUND
|
||||
|
||||
/** @brief Enumeration specifying the status of calls to various APIs in this
|
||||
* module.
|
||||
*/
|
||||
DEFINE_ENUM(CONSTMAP_RESULT, CONSTMAP_RESULT_VALUES);
|
||||
|
||||
typedef struct CONSTMAP_HANDLE_DATA_TAG* CONSTMAP_HANDLE;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Creates a new read-only map from a map handle.
|
||||
*
|
||||
* @param sourceMap The map from which we will populate key,value
|
||||
* into the read-only map.
|
||||
*
|
||||
* @return A valid @c CONSTMAP_HANDLE or @c NULL in case an error occurs.
|
||||
*/
|
||||
MOCKABLE_FUNCTION(, CONSTMAP_HANDLE, ConstMap_Create, MAP_HANDLE, sourceMap);
|
||||
|
||||
/**
|
||||
* @brief Destroy a read-only map. Deallocate memory associated with handle.
|
||||
* @param handle Handle to a read-only map.
|
||||
*/
|
||||
MOCKABLE_FUNCTION(, void, ConstMap_Destroy, CONSTMAP_HANDLE, handle);
|
||||
|
||||
/**
|
||||
* @brief Clone a read-only map from another read-only map.
|
||||
* @param handle Handle to a read-only map.
|
||||
* @return A valid @c CONSTMAP_HANDLE or @c NULL in case an error occurs.
|
||||
*/
|
||||
MOCKABLE_FUNCTION(, CONSTMAP_HANDLE, ConstMap_Clone, CONSTMAP_HANDLE, handle);
|
||||
|
||||
/**
|
||||
* @brief Create a map handle populated from the read-only map.
|
||||
* @param handle Handle to a read-only map.
|
||||
* @return A valid @c MAP_HANDLE or @c NULL in case an error occurs.
|
||||
*
|
||||
* The new MAP_HANDLE needs to be destroyed when it is no longer needed.
|
||||
*/
|
||||
MOCKABLE_FUNCTION(, MAP_HANDLE, ConstMap_CloneWriteable, CONSTMAP_HANDLE, handle);
|
||||
|
||||
/**
|
||||
* @brief This function returns a true if the map contains a key
|
||||
* with the same value the parameter @p key.
|
||||
*
|
||||
* @param handle The handle to an existing map.
|
||||
* @param key The key that the caller wants checked.
|
||||
*
|
||||
* @return The function returns @c true if the key exists
|
||||
* in the map and @c false if key is not found or
|
||||
* parameters are invalid.
|
||||
*/
|
||||
MOCKABLE_FUNCTION(, bool, ConstMap_ContainsKey, CONSTMAP_HANDLE, handle, const char*, key);
|
||||
|
||||
/**
|
||||
* @brief This function returns @c true if at least one <key,value> pair
|
||||
* exists in the map where the entry's value is equal to the
|
||||
* parameter @c value.
|
||||
*
|
||||
* @param handle The handle to an existing map.
|
||||
* @param value The value that the caller wants checked.
|
||||
*
|
||||
* @return The function returns @c true if the value exists
|
||||
* in the map and @c false if value is not found or
|
||||
* parameters are invalid.
|
||||
*/
|
||||
MOCKABLE_FUNCTION(, bool, ConstMap_ContainsValue, CONSTMAP_HANDLE, handle, const char*, value);
|
||||
|
||||
/**
|
||||
* @brief Retrieves the value of a stored key.
|
||||
*
|
||||
* @param handle The handle to an existing map.
|
||||
* @param key The key to be looked up in the map.
|
||||
*
|
||||
* @return Returns @c NULL in case the input arguments are @c NULL or if the
|
||||
* requested key is not found in the map. Returns a pointer to the
|
||||
* key's value otherwise.
|
||||
*/
|
||||
MOCKABLE_FUNCTION(, const char*, ConstMap_GetValue, CONSTMAP_HANDLE, handle, const char*, key);
|
||||
|
||||
/**
|
||||
* @brief Retrieves the complete list of keys and values from the map
|
||||
* in @p values and @p keys. Also writes the size of the list
|
||||
* in @p count.
|
||||
*
|
||||
* @param handle The handle to an existing map.
|
||||
* @param keys The location where the list of keys is to be written.
|
||||
* @param values The location where the list of values is to be written.
|
||||
* @param count The number of stored keys and values is written at the
|
||||
* location indicated by this pointer.
|
||||
*
|
||||
* @return Returns @c CONSTMAP_OK if the keys and values are retrieved
|
||||
* and written successfully or an error code otherwise.
|
||||
*/
|
||||
MOCKABLE_FUNCTION(, CONSTMAP_RESULT, ConstMap_GetInternals, CONSTMAP_HANDLE, handle, const char*const**, keys, const char*const**, values, size_t*, count);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONSTMAP_H */
|
|
@ -1,161 +0,0 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
#ifndef CRT_ABSTRACTIONS_H
|
||||
#define CRT_ABSTRACTIONS_H
|
||||
|
||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <cerrno>
|
||||
#include <cmath>
|
||||
extern "C" {
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
||||
#ifdef QUARKGALILEO
|
||||
#define HAS_STDBOOL
|
||||
#ifdef __cplusplus
|
||||
typedef bool _Bool;
|
||||
#else
|
||||
/*galileo apparently has _Bool and bool as built in types*/
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32_WCE
|
||||
#define HAS_STDBOOL
|
||||
#ifdef __cplusplus
|
||||
#include <cstdbool>
|
||||
/*because C++ doesn't do anything about _Bool... */
|
||||
#define _Bool bool
|
||||
#else
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
#else
|
||||
/* WINCE does not support bool as C datatype */
|
||||
#define __bool_true_false_are_defined 1
|
||||
|
||||
#define HAS_STDBOOL
|
||||
|
||||
#define _Bool bool
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define _CSTDBOOL_
|
||||
#else
|
||||
typedef unsigned char bool;
|
||||
|
||||
#define false 0
|
||||
#define true 1
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#if defined __STDC_VERSION__
|
||||
#if ((__STDC_VERSION__ == 199901L) || (__STDC_VERSION__ == 201000L) || (__STDC_VERSION__ == 201112L))
|
||||
/*C99 compiler or C11*/
|
||||
#define HAS_STDBOOL
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef HAS_STDBOOL
|
||||
#ifdef __cplusplus
|
||||
#define _Bool bool
|
||||
#else
|
||||
typedef unsigned char _Bool;
|
||||
typedef unsigned char bool;
|
||||
#define false 0
|
||||
#define true 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Codes_SRS_CRT_ABSTRACTIONS_99_001:[The module shall not redefine the secure functions implemented by Microsoft CRT.] */
|
||||
/* Codes_SRS_CRT_ABSTRACTIONS_99_040 : [The module shall still compile when building on a Microsoft platform.] */
|
||||
/* Codes_SRS_CRT_ABSTRACTIONS_99_002: [CRTAbstractions module shall expose the following API]*/
|
||||
#ifdef _MSC_VER
|
||||
#else
|
||||
#include "inttypes.h"
|
||||
|
||||
/* Adding definitions from errno.h & crtdefs.h */
|
||||
#if !defined (_TRUNCATE)
|
||||
#define _TRUNCATE ((size_t)-1)
|
||||
#endif /* !defined (_TRUNCATE) */
|
||||
|
||||
#if !defined STRUNCATE
|
||||
#define STRUNCATE 80
|
||||
#endif /* !defined (STRUNCATE) */
|
||||
|
||||
typedef int errno_t;
|
||||
|
||||
extern int strcpy_s(char* dst, size_t dstSizeInBytes, const char* src);
|
||||
extern int strcat_s(char* dst, size_t dstSizeInBytes, const char* src);
|
||||
extern int strncpy_s(char* dst, size_t dstSizeInBytes, const char* src, size_t maxCount);
|
||||
extern int sprintf_s(char* dst, size_t dstSizeInBytes, const char* format, ...);
|
||||
#endif
|
||||
extern unsigned long long strtoull_s(const char* nptr, char** endPtr, int base);
|
||||
extern float strtof_s(const char* nptr, char** endPtr);
|
||||
extern long double strtold_s(const char* nptr, char** endPtr);
|
||||
|
||||
MOCKABLE_FUNCTION(, int, mallocAndStrcpy_s, char**, destination, const char*, source);
|
||||
MOCKABLE_FUNCTION(, int, unsignedIntToString, char*, destination, size_t, destinationSize, unsigned int, value);
|
||||
MOCKABLE_FUNCTION(, int, size_tToString, char*, destination, size_t, destinationSize, size_t, value);
|
||||
/*following logic shall define the ISNAN macro*/
|
||||
/*if runing on Microsoft Visual C compiler, than ISNAN shall be _isnan*/
|
||||
/*else if running on C99 or C11, ISNAN shall be isnan*/
|
||||
/*else if running on C89 ... #error and inform user*/
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define ISNAN _isnan
|
||||
#else
|
||||
#if defined __STDC_VERSION__
|
||||
#if ((__STDC_VERSION__ == 199901L) || (__STDC_VERSION__ == 201000L) || (__STDC_VERSION__ == 201112L))
|
||||
/*C99 compiler or C11*/
|
||||
#define ISNAN isnan
|
||||
#else
|
||||
#error update this file to contain the latest C standard.
|
||||
#endif
|
||||
#else
|
||||
#ifdef __cplusplus
|
||||
/*C++ defines isnan... in C11*/
|
||||
extern "C++" {
|
||||
#define ISNAN std::isnan
|
||||
}
|
||||
#else
|
||||
#error unknown (or C89) compiler, provide ISNAN with the same meaning as isnan in C99 standard
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define INT64_PRINTF "%I64d"
|
||||
#else
|
||||
#if defined __STDC_VERSION__
|
||||
#if ((__STDC_VERSION__ == 199901L) || (__STDC_VERSION__ == 201000L) || (__STDC_VERSION__ == 201112L))
|
||||
/*C99 compiler or C11*/
|
||||
#define INT64_PRINTF "%" PRId64 ""
|
||||
#else
|
||||
#error update this file to contain the latest C standard.
|
||||
#endif
|
||||
#else
|
||||
#ifdef __cplusplus
|
||||
#define INT64_PRINTF "%" PRId64 ""
|
||||
#else
|
||||
#error unknown (or C89) compiler, provide INT64_PRINTF with the same meaning as PRIdN in C99 standard
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CRT_ABSTRACTIONS_H */
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,202 +0,0 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
/** @file map.h
|
||||
* @brief Map is a module that implements a dictionary of @c STRING_HANDLE
|
||||
* keys to @c STRING_HANDLE values.
|
||||
*/
|
||||
|
||||
#ifndef MAP_H
|
||||
#define MAP_H
|
||||
|
||||
#include "azure_c_shared_utility/macro_utils.h"
|
||||
#include "azure_c_shared_utility/strings.h"
|
||||
#include "azure_c_shared_utility/crt_abstractions.h"
|
||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <cstddef>
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#include <stddef.h>
|
||||
#endif
|
||||
|
||||
#define MAP_RESULT_VALUES \
|
||||
MAP_OK, \
|
||||
MAP_ERROR, \
|
||||
MAP_INVALIDARG, \
|
||||
MAP_KEYEXISTS, \
|
||||
MAP_KEYNOTFOUND, \
|
||||
MAP_FILTER_REJECT
|
||||
|
||||
/** @brief Enumeration specifying the status of calls to various APIs in this
|
||||
* module.
|
||||
*/
|
||||
DEFINE_ENUM(MAP_RESULT, MAP_RESULT_VALUES);
|
||||
|
||||
typedef struct MAP_HANDLE_DATA_TAG* MAP_HANDLE;
|
||||
|
||||
typedef int (*MAP_FILTER_CALLBACK)(const char* mapProperty, const char* mapValue);
|
||||
|
||||
/**
|
||||
* @brief Creates a new, empty map.
|
||||
*
|
||||
* @param mapFilterFunc A callback function supplied by the caller that is
|
||||
* invoked during calls to ::Map_Add and
|
||||
* ::Map_AddOrUpdate to provide the caller an
|
||||
* opportunity to indicate whether the new entry or
|
||||
* the update to an existing entry can be made or not.
|
||||
* The callback function can request that the operation
|
||||
* be canceled by returning a non-zero value from the
|
||||
* callback.
|
||||
*
|
||||
* @return A valid @c MAP_HANDLE or @c NULL in case an error occurs.
|
||||
*/
|
||||
MOCKABLE_FUNCTION(, MAP_HANDLE, Map_Create, MAP_FILTER_CALLBACK, mapFilterFunc);
|
||||
|
||||
/**
|
||||
* @brief Release all resources associated with the map.
|
||||
*
|
||||
* @param handle The handle to an existing map.
|
||||
*/
|
||||
MOCKABLE_FUNCTION(, void, Map_Destroy, MAP_HANDLE, handle);
|
||||
|
||||
/**
|
||||
* @brief Creates a copy of the map indicated by @p handle and returns a
|
||||
* handle to it.
|
||||
*
|
||||
* @param handle The handle to an existing map.
|
||||
*
|
||||
* @return A valid @c MAP_HANDLE to the cloned copy of the map or @c NULL
|
||||
* in case an error occurs.
|
||||
*/
|
||||
MOCKABLE_FUNCTION(, MAP_HANDLE, Map_Clone, MAP_HANDLE, handle);
|
||||
|
||||
/**
|
||||
* @brief Adds a key/value pair to the map.
|
||||
*
|
||||
* @param handle The handle to an existing map.
|
||||
* @param key The @c key to be used for this map entry.
|
||||
* @param value The @c value to be associated with @p key.
|
||||
*
|
||||
* If a non-NULL pointer to a callback function was supplied
|
||||
* via the @c mapFilterFunc parameter when ::Map_Create was
|
||||
* called then that callback is invoked when a new entry is
|
||||
* added and if the callback returns a non-zero value then
|
||||
* the function cancels the add operation and returns
|
||||
* @c MAP_FILTER_REJECT.
|
||||
*
|
||||
* @return If any of the input parameters are @c NULL then this function
|
||||
* returns @c MAP_INVALID_ARG. If the key already exists in the
|
||||
* map then @c MAP_KEYEXISTS is returned. If the filter function
|
||||
* associated with the map rejects the entry then
|
||||
* @c MAP_FILTER_REJECT is returned. In case an error occurs when
|
||||
* the new key is added to the map the function returns @c MAP_ERROR.
|
||||
* If everything goes well then @c MAP_OK is returned.
|
||||
*/
|
||||
MOCKABLE_FUNCTION(, MAP_RESULT, Map_Add, MAP_HANDLE, handle, const char*, key, const char*, value);
|
||||
|
||||
/**
|
||||
* @brief Adds/updates a key/value pair to the map.
|
||||
*
|
||||
* @param handle The handle to an existing map.
|
||||
* @param key The @c key to be used for this map entry.
|
||||
* @param value The @c value to be associated with @p key.
|
||||
*
|
||||
* This function behaves exactly like ::Map_Add except that if the key
|
||||
* already exists in the map then it overwrites the value with the
|
||||
* supplied value instead of returning an error. If a non-NULL pointer
|
||||
* to a callback function was supplied via the @c mapFilterFunc parameter
|
||||
* when ::Map_Create was called then that callback is invoked when a new
|
||||
* entry is added or when an existing entry is updated and if the
|
||||
* callback returns a non-zero value then the function cancels the
|
||||
* add/update operation and returns @c MAP_FILTER_REJECT.
|
||||
*
|
||||
* @return If any of the input parameters are @c NULL then this function
|
||||
* returns @c MAP_INVALID_ARG. If the filter function associated
|
||||
* with the map rejects the entry then @c MAP_FILTER_REJECT is
|
||||
* returned. In case an error occurs when the new key is
|
||||
* added/updated in the map the function returns @c MAP_ERROR. If
|
||||
* everything goes well then @c MAP_OK is returned.
|
||||
*/
|
||||
MOCKABLE_FUNCTION(, MAP_RESULT, Map_AddOrUpdate, MAP_HANDLE, handle, const char*, key, const char*, value);
|
||||
|
||||
/**
|
||||
* @brief Removes a key and its associated value from the map.
|
||||
*
|
||||
* @param handle The handle to an existing map.
|
||||
* @param key The @c key of the item to be deleted.
|
||||
*
|
||||
* @return Returns @c MAP_OK if the key was deleted successfully or an
|
||||
* error code otherwise.
|
||||
*/
|
||||
MOCKABLE_FUNCTION(, MAP_RESULT, Map_Delete, MAP_HANDLE, handle, const char*, key);
|
||||
|
||||
/**
|
||||
* @brief This function returns a boolean value in @p keyExists if the map
|
||||
* contains a key with the same value the parameter @p key.
|
||||
*
|
||||
* @param handle The handle to an existing map.
|
||||
* @param key The key that the caller wants checked.
|
||||
* @param keyExists The function writes @c true at the address pointed at
|
||||
* by this parameter if the key exists in the map and
|
||||
* @c false otherwise.
|
||||
*
|
||||
* @return Returns @c MAP_OK if the check was performed successfully or an
|
||||
* error code otherwise.
|
||||
*/
|
||||
MOCKABLE_FUNCTION(, MAP_RESULT, Map_ContainsKey, MAP_HANDLE, handle, const char*, key, bool*, keyExists);
|
||||
|
||||
/**
|
||||
* @brief This function returns @c true in @p valueExists if at
|
||||
* least one <key,value> pair exists in the map where the entry's
|
||||
* value is equal to the parameter @c value.
|
||||
*
|
||||
* @param handle The handle to an existing map.
|
||||
* @param value The value that the caller wants checked.
|
||||
* @param valueExists The function writes @c true at the address pointed at
|
||||
* by this parameter if the value exists in the map and
|
||||
* @c false otherwise.
|
||||
*
|
||||
* @return Returns @c MAP_OK if the check was performed successfully or an
|
||||
* error code otherwise.
|
||||
*/
|
||||
MOCKABLE_FUNCTION(, MAP_RESULT, Map_ContainsValue, MAP_HANDLE, handle, const char*, value, bool*, valueExists);
|
||||
|
||||
/**
|
||||
* @brief Retrieves the value of a stored key.
|
||||
*
|
||||
* @param handle The handle to an existing map.
|
||||
* @param key The key to be looked up in the map.
|
||||
*
|
||||
* @return Returns @c NULL in case the input arguments are @c NULL or if the
|
||||
* requested key is not found in the map. Returns a pointer to the
|
||||
* key's value otherwise.
|
||||
*/
|
||||
MOCKABLE_FUNCTION(, const char*, Map_GetValueFromKey, MAP_HANDLE, handle, const char*, key);
|
||||
|
||||
/**
|
||||
* @brief Retrieves the complete list of keys and values from the map
|
||||
* in @p values and @p keys. Also writes the size of the list
|
||||
* in @p count.
|
||||
*
|
||||
* @param handle The handle to an existing map.
|
||||
* @param keys The location where the list of keys is to be written.
|
||||
* @param values The location where the list of values is to be written.
|
||||
* @param count The number of stored keys and values is written at the
|
||||
* location indicated by this pointer.
|
||||
*
|
||||
* @return Returns @c MAP_OK if the keys and values are retrieved and written
|
||||
* successfully or an error code otherwise.
|
||||
*/
|
||||
MOCKABLE_FUNCTION(, MAP_RESULT, Map_GetInternals, MAP_HANDLE, handle, const char*const**, keys, const char*const**, values, size_t*, count);
|
||||
|
||||
/*this API creates a JSON object from the content of the map*/
|
||||
MOCKABLE_FUNCTION(, STRING_HANDLE, Map_ToJSON, MAP_HANDLE, handle);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* MAP_H */
|
|
@ -1,45 +0,0 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
#ifndef STRINGS_H
|
||||
#define STRINGS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <cstddef>
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#include <stddef.h>
|
||||
#endif
|
||||
|
||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
||||
|
||||
typedef struct STRING_TAG* STRING_HANDLE;
|
||||
|
||||
MOCKABLE_FUNCTION(, STRING_HANDLE, STRING_new);
|
||||
MOCKABLE_FUNCTION(, STRING_HANDLE, STRING_clone, STRING_HANDLE, handle);
|
||||
MOCKABLE_FUNCTION(, STRING_HANDLE, STRING_construct, const char*, psz);
|
||||
MOCKABLE_FUNCTION(, STRING_HANDLE, STRING_construct_n, const char*, psz, size_t, n);
|
||||
MOCKABLE_FUNCTION(, STRING_HANDLE, STRING_new_with_memory, const char*, memory);
|
||||
MOCKABLE_FUNCTION(, STRING_HANDLE, STRING_new_quoted, const char*, source);
|
||||
MOCKABLE_FUNCTION(, STRING_HANDLE, STRING_new_JSON, const char*, source);
|
||||
MOCKABLE_FUNCTION(, STRING_HANDLE, STRING_from_byte_array, const unsigned char*, source, size_t, size);
|
||||
MOCKABLE_FUNCTION(, void, STRING_delete, STRING_HANDLE, handle);
|
||||
MOCKABLE_FUNCTION(, int, STRING_concat, STRING_HANDLE, handle, const char*, s2);
|
||||
MOCKABLE_FUNCTION(, int, STRING_concat_with_STRING, STRING_HANDLE, s1, STRING_HANDLE, s2);
|
||||
MOCKABLE_FUNCTION(, int, STRING_quote, STRING_HANDLE, handle);
|
||||
MOCKABLE_FUNCTION(, int, STRING_copy, STRING_HANDLE, s1, const char*, s2);
|
||||
MOCKABLE_FUNCTION(, int, STRING_copy_n, STRING_HANDLE, s1, const char*, s2, size_t, n);
|
||||
MOCKABLE_FUNCTION(, const char*, STRING_c_str, STRING_HANDLE, handle);
|
||||
MOCKABLE_FUNCTION(, int, STRING_empty, STRING_HANDLE, handle);
|
||||
MOCKABLE_FUNCTION(, size_t, STRING_length, STRING_HANDLE, handle);
|
||||
MOCKABLE_FUNCTION(, int, STRING_compare, STRING_HANDLE, s1, STRING_HANDLE, s2);
|
||||
|
||||
extern STRING_HANDLE STRING_construct_sprintf(const char* format, ...);
|
||||
extern int STRING_sprintf(STRING_HANDLE s1, const char* format, ...);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*STRINGS_H*/
|
|
@ -1,33 +0,0 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
#undef MOCKABLE_FUNCTION
|
||||
|
||||
/* This header is meant to be included by production code headers, so that the MOCKABLE_FUNCTION gets enabled. */
|
||||
/*
|
||||
If you are porting to a new platform and do not want to build the tests, but only the production code,
|
||||
simply make sure that this file is in the include path (either by copying it to your inc folder or
|
||||
by adjusting the include paths).
|
||||
*/
|
||||
|
||||
#ifdef ENABLE_MOCKS
|
||||
|
||||
/* Codes_SRS_UMOCK_C_LIB_01_001: [MOCKABLE_FUNCTION shall be used to wrap function definition allowing the user to declare a function that can be mocked.]*/
|
||||
#define MOCKABLE_FUNCTION(modifiers, result, function, ...) \
|
||||
MOCKABLE_FUNCTION_UMOCK_INTERNAL_WITH_MOCK(modifiers, result, function, __VA_ARGS__)
|
||||
|
||||
#include "umock_c.h"
|
||||
|
||||
#else
|
||||
|
||||
#include "azure_c_shared_utility/macro_utils.h"
|
||||
|
||||
#define UMOCK_C_PROD_ARG_IN_SIGNATURE(count, arg_type, arg_name) arg_type arg_name IFCOMMA(count)
|
||||
|
||||
/* Codes_SRS_UMOCK_C_LIB_01_002: [The macro shall generate a function signature in case ENABLE_MOCKS is not defined.] */
|
||||
/* Codes_SRS_UMOCK_C_LIB_01_005: [**If ENABLE_MOCKS is not defined, MOCKABLE_FUNCTION shall only generate a declaration for the function.] */
|
||||
/* Codes_SRS_UMOCK_C_LIB_01_001: [MOCKABLE_FUNCTION shall be used to wrap function definition allowing the user to declare a function that can be mocked.]*/
|
||||
#define MOCKABLE_FUNCTION(modifiers, result, function, ...) \
|
||||
result modifiers function(IF(COUNT_ARG(__VA_ARGS__),,void) FOR_EACH_2_COUNTED(UMOCK_C_PROD_ARG_IN_SIGNATURE, __VA_ARGS__));
|
||||
|
||||
#endif
|
|
@ -1,49 +0,0 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
#ifndef VECTOR_H
|
||||
#define VECTOR_H
|
||||
|
||||
#include "azure_c_shared_utility/crt_abstractions.h"
|
||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <cstddef>
|
||||
#include <cstdbool>
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
typedef struct VECTOR_TAG* VECTOR_HANDLE;
|
||||
|
||||
typedef bool(*PREDICATE_FUNCTION)(const void* element, const void* value);
|
||||
|
||||
/* creation */
|
||||
MOCKABLE_FUNCTION(, VECTOR_HANDLE, VECTOR_create, size_t, elementSize);
|
||||
MOCKABLE_FUNCTION(, void, VECTOR_destroy, VECTOR_HANDLE, handle);
|
||||
|
||||
/* insertion */
|
||||
MOCKABLE_FUNCTION(, int, VECTOR_push_back, VECTOR_HANDLE, handle, const void*, elements, size_t, numElements);
|
||||
|
||||
/* removal */
|
||||
MOCKABLE_FUNCTION(, void, VECTOR_erase, VECTOR_HANDLE, handle, void*, elements, size_t, numElements);
|
||||
MOCKABLE_FUNCTION(, void, VECTOR_clear, VECTOR_HANDLE, handle);
|
||||
|
||||
/* access */
|
||||
MOCKABLE_FUNCTION(, void*, VECTOR_element, const VECTOR_HANDLE, handle, size_t, index);
|
||||
MOCKABLE_FUNCTION(, void*, VECTOR_front, const VECTOR_HANDLE, handle);
|
||||
MOCKABLE_FUNCTION(, void*, VECTOR_back, const VECTOR_HANDLE, handle);
|
||||
MOCKABLE_FUNCTION(, void*, VECTOR_find_if, const VECTOR_HANDLE, handle, PREDICATE_FUNCTION, pred, const void*, value);
|
||||
|
||||
/* capacity */
|
||||
MOCKABLE_FUNCTION(, size_t, VECTOR_size, const VECTOR_HANDLE, handle);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#else
|
||||
#endif
|
||||
|
||||
#endif /* VECTOR_H */
|
157
inc/broker.h
157
inc/broker.h
|
@ -1,157 +0,0 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
/** @file broker.h
|
||||
* @brief Library for configuring and using the gateway's message broker.
|
||||
*
|
||||
* @details This is the API to create a reference counted and thread safe
|
||||
* gateway message broker. The broker sends messages to other
|
||||
* modules. Messages published to the broker have a bag of
|
||||
* properties (name, value) and an opaque array of bytes that
|
||||
* constitute the message content.
|
||||
*/
|
||||
|
||||
#ifndef BROKER_H
|
||||
#define BROKER_H
|
||||
|
||||
/** @brief Struct representing a message broker. */
|
||||
typedef struct BROKER_HANDLE_DATA_TAG* BROKER_HANDLE;
|
||||
|
||||
#include "azure_c_shared_utility/macro_utils.h"
|
||||
#include "message.h"
|
||||
#include "module.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <cstddef>
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#include <stddef.h>
|
||||
#endif
|
||||
|
||||
/** @brief Link Data with #MODULE_HANDLE for source and sink.
|
||||
*/
|
||||
typedef struct BROKER_LINK_DATA_TAG {
|
||||
/** @brief #MODULE_HANDLE representing the module generating/publishing messages.
|
||||
*/
|
||||
MODULE_HANDLE module_source_handle;
|
||||
/** @brief #MODULE_HANDLE representing the module receiving messages.
|
||||
*/
|
||||
MODULE_HANDLE module_sink_handle;
|
||||
} BROKER_LINK_DATA;
|
||||
|
||||
#define BROKER_RESULT_VALUES \
|
||||
BROKER_OK, \
|
||||
BROKER_ERROR, \
|
||||
BROKER_ADD_LINK_ERROR, \
|
||||
BROKER_REMOVE_LINK_ERROR, \
|
||||
BROKER_INVALIDARG
|
||||
|
||||
/** @brief Enumeration describing the result of ::Broker_Publish,
|
||||
* ::Broker_AddModule, ::Broker_AddLink, and ::Broker_RemoveModule.
|
||||
*/
|
||||
DEFINE_ENUM(BROKER_RESULT, BROKER_RESULT_VALUES);
|
||||
|
||||
/** @brief Creates a new message broker.
|
||||
*
|
||||
* @return A valid #BROKER_HANDLE upon success, or @c NULL upon failure.
|
||||
*/
|
||||
extern BROKER_HANDLE Broker_Create(void);
|
||||
|
||||
/** @brief Increments the reference count of a message broker.
|
||||
*
|
||||
* @details This function will simply increment the internal reference
|
||||
* count of the provided #BROKER_HANDLE.
|
||||
*
|
||||
* @param broker The #BROKER_HANDLE to be cloned.
|
||||
*/
|
||||
extern void Broker_IncRef(BROKER_HANDLE broker);
|
||||
|
||||
/** @brief Decrements the reference count of a message broker.
|
||||
*
|
||||
* @details This function will simply decrement the internal reference
|
||||
* count of the provided #BROKER_HANDLE, destroying the message
|
||||
* broker when the reference count reaches 0.
|
||||
*
|
||||
* @param broker The #BROKER_HANDLE whose ref count will be decremented.
|
||||
*/
|
||||
extern void Broker_DecRef(BROKER_HANDLE broker);
|
||||
|
||||
/** @brief Publishes a message to the message broker.
|
||||
*
|
||||
* @details For details about threading with regard to the message broker
|
||||
* and modules connected to it, see
|
||||
* <a href="https://github.com/Azure/azure-iot-gateway-sdk/blob/develop/core/devdoc/broker_hld.md">Broker High Level Design Documentation</a>.
|
||||
*
|
||||
* @param broker The #BROKER_HANDLE onto which the message will be
|
||||
* published.
|
||||
* @param source The #MODULE_HANDLE from which the message will be
|
||||
* published. The broker will not publish the message to this
|
||||
* module. (optional, may be NULL)
|
||||
* @param message The #MESSAGE_HANDLE representing the message to be
|
||||
* published.
|
||||
*
|
||||
* @return A #BROKER_RESULT describing the result of the function.
|
||||
*/
|
||||
extern BROKER_RESULT Broker_Publish(BROKER_HANDLE broker, MODULE_HANDLE source, MESSAGE_HANDLE message);
|
||||
|
||||
/** @brief Adds a module to the message broker.
|
||||
*
|
||||
* @details For details about threading with regard to the message broker
|
||||
* and modules connected to it, see
|
||||
* <a href="https://github.com/Azure/azure-iot-gateway-sdk/blob/develop/core/devdoc/broker_hld.md">Broker High Level Design Documentation</a>.
|
||||
*
|
||||
* @param broker The #BROKER_HANDLE onto which the module will be
|
||||
* added.
|
||||
* @param module The #MODULE for the module that will be added
|
||||
* to this message broker.
|
||||
*
|
||||
* @return A #BROKER_RESULT describing the result of the function.
|
||||
*/
|
||||
extern BROKER_RESULT Broker_AddModule(BROKER_HANDLE broker, const MODULE* module);
|
||||
|
||||
/** @brief Removes a module from the message broker.
|
||||
*
|
||||
* @param broker The #BROKER_HANDLE from which the module will be removed.
|
||||
* @param module The #MODULE of the module to be removed.
|
||||
*
|
||||
* @return A #BROKER_RESULT describing the result of the function.
|
||||
*/
|
||||
extern BROKER_RESULT Broker_RemoveModule(BROKER_HANDLE broker, const MODULE* module);
|
||||
|
||||
/** @brief Adds a route to the message broker.
|
||||
*
|
||||
* @details For details about threading with regard to the message broker
|
||||
* and modules connected to it, see
|
||||
* <a href="https://github.com/Azure/azure-iot-gateway-sdk/blob/develop/core/devdoc/broker_hld.md">Broker High Level Design Documentation</a>.
|
||||
*
|
||||
* @param broker The #BROKER_HANDLE onto which the module will be
|
||||
* added.
|
||||
* @param link The #BROKER_LINK_DATA for the link that will be added
|
||||
* to this message broker.
|
||||
*
|
||||
* @return A #BROKER_RESULT describing the result of the function.
|
||||
*/
|
||||
extern BROKER_RESULT Broker_AddLink(BROKER_HANDLE broker, const BROKER_LINK_DATA* link);
|
||||
|
||||
/** @brief Removes a route from the message broker.
|
||||
*
|
||||
* @param broker The #BROKER_HANDLE from which the link will be removed.
|
||||
* @param link The #BROKER_LINK_DATA of the link to be removed.
|
||||
*
|
||||
* @return A #BROKER_RESULT describing the result of the function.
|
||||
*/
|
||||
extern BROKER_RESULT Broker_RemoveLink(BROKER_HANDLE broker, const BROKER_LINK_DATA* link);
|
||||
|
||||
/** @brief Disposes of resources allocated by a message broker.
|
||||
*
|
||||
* @param broker The #BROKER_HANDLE to be destroyed.
|
||||
*/
|
||||
extern void Broker_Destroy(BROKER_HANDLE broker);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /*BROKER_H*/
|
236
inc/gateway.h
236
inc/gateway.h
|
@ -1,236 +0,0 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
/** @file gateway.h
|
||||
* @brief Library that allows a user to create and configure a gateway.
|
||||
*
|
||||
* @details The Gateway library provides a mechanism for creating and
|
||||
* destroying a gateway, as well as adding and removing modules.
|
||||
*/
|
||||
|
||||
#ifndef GATEWAY_H
|
||||
#define GATEWAY_H
|
||||
|
||||
#include "azure_c_shared_utility/macro_utils.h"
|
||||
#include "azure_c_shared_utility/vector.h"
|
||||
#include "module.h"
|
||||
#include "module_loader.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#define GATEWAY_ADD_LINK_RESULT_VALUES \
|
||||
GATEWAY_ADD_LINK_SUCCESS, \
|
||||
GATEWAY_ADD_LINK_ERROR, \
|
||||
GATEWAY_ADD_LINK_INVALID_ARG
|
||||
|
||||
/** @brief Enumeration describing the result of ::Gateway_AddLink.
|
||||
*/
|
||||
DEFINE_ENUM(GATEWAY_ADD_LINK_RESULT, GATEWAY_ADD_LINK_RESULT_VALUES);
|
||||
|
||||
#define GATEWAY_START_RESULT_VALUES \
|
||||
GATEWAY_START_SUCCESS, \
|
||||
GATEWAY_START_INVALID_ARGS
|
||||
|
||||
/** @brief Enumeration describing the result of ::Gateway_Start.
|
||||
*/
|
||||
DEFINE_ENUM(GATEWAY_START_RESULT, GATEWAY_START_RESULT_VALUES);
|
||||
|
||||
/** @brief Struct representing a single link for a gateway. */
|
||||
typedef struct GATEWAY_LINK_ENTRY_TAG
|
||||
{
|
||||
/** @brief The name of the module which is going to send messages. */
|
||||
const char* module_source;
|
||||
|
||||
/** @brief The name of the module which is going to receive messages. */
|
||||
const char* module_sink;
|
||||
} GATEWAY_LINK_ENTRY;
|
||||
|
||||
/** @brief Struct representing a particular gateway. */
|
||||
typedef struct GATEWAY_HANDLE_DATA_TAG* GATEWAY_HANDLE;
|
||||
|
||||
/** @brief Struct representing the loader and entrypoint
|
||||
* to be used for a specific module.
|
||||
*/
|
||||
typedef struct GATEWAY_MODULE_LOADER_INFO_TAG
|
||||
{
|
||||
/** @brief Pointer to the module loader to be used for
|
||||
* loading this module.
|
||||
*/
|
||||
const MODULE_LOADER* loader;
|
||||
|
||||
/** @brief Pointer to the entrypoint for this module.
|
||||
*/
|
||||
void* entrypoint;
|
||||
} GATEWAY_MODULE_LOADER_INFO;
|
||||
|
||||
/** @brief Struct representing a single entry of the #GATEWAY_PROPERTIES.
|
||||
*/
|
||||
typedef struct GATEWAY_MODULES_ENTRY_TAG
|
||||
{
|
||||
/** @brief The (possibly @c NULL) name of the module */
|
||||
const char* module_name;
|
||||
|
||||
/** @brief The module loader information for this module */
|
||||
GATEWAY_MODULE_LOADER_INFO module_loader_info;
|
||||
|
||||
/** @brief The user-defined configuration object for the module */
|
||||
const void* module_configuration;
|
||||
} GATEWAY_MODULES_ENTRY;
|
||||
|
||||
/** @brief Struct representing the properties that should be used when
|
||||
* creating a module; each entry of the @c VECTOR_HANDLE being a
|
||||
* #GATEWAY_MODULES_ENTRY.
|
||||
*/
|
||||
typedef struct GATEWAY_PROPERTIES_DATA_TAG
|
||||
{
|
||||
/** @brief Vector of #GATEWAY_MODULES_ENTRY objects. */
|
||||
VECTOR_HANDLE gateway_modules;
|
||||
|
||||
/** @brief Vector of #GATEWAY_LINK_ENTRY objects. */
|
||||
VECTOR_HANDLE gateway_links;
|
||||
} GATEWAY_PROPERTIES;
|
||||
|
||||
/** @brief Creates a gateway using a JSON configuration file as input
|
||||
* which describes each module. Each module described in the
|
||||
* configuration must support Module_CreateFromJson.
|
||||
*
|
||||
* @param file_path Path to the JSON configuration file for this
|
||||
* gateway.
|
||||
*
|
||||
* Sample JSON configuration file:
|
||||
*
|
||||
* {
|
||||
* "modules" :
|
||||
* [
|
||||
* {
|
||||
"name": "sensor",
|
||||
"loader": {
|
||||
"name": "dotnet",
|
||||
"entrypoint": {
|
||||
"class.name": "Microsoft.Azure.Gateway.SensorModule",
|
||||
"assembly.path": "./bin/Microsoft.Azure.Gateway.Modules.dll"
|
||||
}
|
||||
},
|
||||
"args" : {
|
||||
"power.level": 5
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "logger",
|
||||
"loader": {
|
||||
"name": "native",
|
||||
"entrypoint": {
|
||||
"module.path": "./bin/liblogger.so"
|
||||
}
|
||||
},
|
||||
"args": {
|
||||
"filename": "/var/logs/gateway-log.json"
|
||||
}
|
||||
}
|
||||
* ],
|
||||
* "links":
|
||||
* [
|
||||
* {
|
||||
* "source": "sensor",
|
||||
* "sink": "logger"
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
*
|
||||
* @return A non-NULL #GATEWAY_HANDLE that can be used to manage the
|
||||
* gateway or @c NULL on failure.
|
||||
*/
|
||||
extern GATEWAY_HANDLE Gateway_CreateFromJson(const char* file_path);
|
||||
|
||||
/** @brief Creates a new gateway using the provided #GATEWAY_PROPERTIES.
|
||||
*
|
||||
* @param properties #GATEWAY_PROPERTIES structure containing
|
||||
* specific module properties and information.
|
||||
*
|
||||
* @return A non-NULL #GATEWAY_HANDLE that can be used to manage the
|
||||
* gateway or @c NULL on failure.
|
||||
*/
|
||||
extern GATEWAY_HANDLE Gateway_Create(const GATEWAY_PROPERTIES* properties);
|
||||
|
||||
/** @brief Tell the Gateway it's ready to start.
|
||||
*
|
||||
* @param gw #GATEWAY_HANDLE to be destroyed.
|
||||
*
|
||||
* @return A #GATEWAY_START_RESULT to report the result of the start
|
||||
*/
|
||||
extern GATEWAY_START_RESULT Gateway_Start(GATEWAY_HANDLE gw);
|
||||
|
||||
/** @brief Destroys the gateway and disposes of all associated data.
|
||||
*
|
||||
* @param gw #GATEWAY_HANDLE to be destroyed.
|
||||
*/
|
||||
extern void Gateway_Destroy(GATEWAY_HANDLE gw);
|
||||
|
||||
/** @brief Creates a new module based on the GATEWAY_MODULES_ENTRY*.
|
||||
*
|
||||
* @param gw Pointer to a #GATEWAY_HANDLE to add the Module onto.
|
||||
* @param entry Pointer to a #GATEWAY_MODULES_ENTRY structure
|
||||
* describing the module.
|
||||
*
|
||||
* @return A non-NULL #MODULE_HANDLE to the newly created and added
|
||||
* Module, or @c NULL on failure.
|
||||
*/
|
||||
extern MODULE_HANDLE Gateway_AddModule(GATEWAY_HANDLE gw, const GATEWAY_MODULES_ENTRY* entry);
|
||||
|
||||
/** @brief Tells a module that the gateway is ready for it to start.
|
||||
*
|
||||
* @param gw Pointer to a #GATEWAY_HANDLE from which to remove the
|
||||
* Module.
|
||||
* @param module Pointer to a #MODULE_HANDLE that needs to be removed.
|
||||
*/
|
||||
extern void Gateway_StartModule(GATEWAY_HANDLE gw, MODULE_HANDLE module);
|
||||
|
||||
|
||||
/** @brief Removes the provided module from the gateway and all links that
|
||||
* involves this module.
|
||||
*
|
||||
* @param gw Pointer to a #GATEWAY_HANDLE from which to remove the
|
||||
* Module.
|
||||
* @param module Pointer to a #MODULE_HANDLE that needs to be removed.
|
||||
*/
|
||||
extern void Gateway_RemoveModule(GATEWAY_HANDLE gw, MODULE_HANDLE module);
|
||||
|
||||
/** @brief Removes module by its unique name
|
||||
*
|
||||
* @param gw Pointer to a #GATEWAY_HANDLE from which to remove
|
||||
* the module.
|
||||
* @param module_name A C string representing the name of module to be
|
||||
* removed
|
||||
*
|
||||
* @return 0 on success and a non-zero value when an error occurs.
|
||||
*/
|
||||
extern int Gateway_RemoveModuleByName(GATEWAY_HANDLE gw, const char *module_name);
|
||||
|
||||
/** @brief Adds a link to a gateway message broker.
|
||||
*
|
||||
* @param gw Pointer to a #GATEWAY_HANDLE from which link is
|
||||
* going to be added.
|
||||
*
|
||||
* @param entryLink Pointer to a #GATEWAY_LINK_ENTRY to be added.
|
||||
*
|
||||
* @return A GATEWAY_ADD_LINK_RESULT with the operation result.
|
||||
*/
|
||||
extern GATEWAY_ADD_LINK_RESULT Gateway_AddLink(GATEWAY_HANDLE gw, const GATEWAY_LINK_ENTRY* entryLink);
|
||||
|
||||
/** @brief Remove a link from a gateway message broker.
|
||||
*
|
||||
* @param gw Pointer to a #GATEWAY_HANDLE from which link is
|
||||
* going to be removed.
|
||||
*
|
||||
* @param entryLink Pointer to a #GATEWAY_LINK_ENTRY to be removed.
|
||||
*/
|
||||
extern void Gateway_RemoveLink(GATEWAY_HANDLE gw, const GATEWAY_LINK_ENTRY* entryLink);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // GATEWAY_H
|
213
inc/message.h
213
inc/message.h
|
@ -1,213 +0,0 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
/** @file message.h
|
||||
*
|
||||
* @brief Defines structures and function prototypes for creating,
|
||||
* inspecting and disposing of messages published to the
|
||||
* message broker.
|
||||
*
|
||||
* @details A message essentially has two components:
|
||||
* - Properties represented as key/value pairs where both the
|
||||
* key and value are strings
|
||||
* - The content of the message which is simply a memory buffer
|
||||
* (a @c BUFFER_HANDLE)
|
||||
*
|
||||
* This header provides functions that enable the creation,
|
||||
* inspection and destruction of messages. A message is represented
|
||||
* via a #MESSAGE_HANDLE which is an opaque reference to a message
|
||||
* instance. Messages are immutable and reference counted; their
|
||||
* lifetime is managed via the #Message_Clone and #Message_Destroy
|
||||
* APIs which atomically increment and decrement the reference
|
||||
* count respectively. #Message_Destroy deallocates the message
|
||||
* completely when the reference count becomes zero.
|
||||
*/
|
||||
|
||||
#ifndef MESSAGE_H
|
||||
#define MESSAGE_H
|
||||
|
||||
#include "azure_c_shared_utility/macro_utils.h"
|
||||
#include "azure_c_shared_utility/map.h"
|
||||
#include "azure_c_shared_utility/constmap.h"
|
||||
#include "azure_c_shared_utility/constbuffer.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#endif
|
||||
|
||||
/** @brief Struct representing a particular message. */
|
||||
typedef struct MESSAGE_HANDLE_DATA_TAG* MESSAGE_HANDLE;
|
||||
|
||||
/** @brief Struct defining the Message configuration; messages are constructed
|
||||
* using this structure.
|
||||
*/
|
||||
typedef struct MESSAGE_CONFIG_TAG
|
||||
{
|
||||
/** @brief Specifies the size of the buffer pointed at by @c source. This
|
||||
* can be zero when the message has only properties and no
|
||||
* content. It is an error for the size to be greater than zero
|
||||
* when @c source is equal to @c NULL.
|
||||
*/
|
||||
size_t size;
|
||||
|
||||
/** @brief Pointer to the buffer containing the data that will be the
|
||||
* content of this message. This can be @c NULL when @c size is
|
||||
* zero.
|
||||
*/
|
||||
const unsigned char* source;
|
||||
|
||||
/** @brief A collection of key/value pairs where both the key and value
|
||||
* are strings representing the properties of this message. This
|
||||
* field must not be @c NULL.
|
||||
*/
|
||||
MAP_HANDLE sourceProperties;
|
||||
}MESSAGE_CONFIG;
|
||||
|
||||
/** @brief Struct defining the Message buffer configuration. */
|
||||
typedef struct MESSAGE_BUFFER_CONFIG_TAG
|
||||
{
|
||||
/** @brief The buffer containing the data that will be the content of the
|
||||
* message.
|
||||
*/
|
||||
CONSTBUFFER_HANDLE sourceContent;
|
||||
|
||||
/** @brief A collection of key/value pairs where both the key and value
|
||||
* are strings representing the properties of this message. This
|
||||
* field must not be @c NULL.
|
||||
*/
|
||||
MAP_HANDLE sourceProperties;
|
||||
}MESSAGE_BUFFER_CONFIG;
|
||||
|
||||
/** @brief Creates a new reference counted message from a #MESSAGE_CONFIG
|
||||
* structure with the reference count initialized to 1.
|
||||
*
|
||||
* @details This function will create its own @c CONSTBUFFER and
|
||||
* @c ConstMap with copies of the @c source and
|
||||
* @c sourceProperties contained within the #MESSAGE_CONFIG
|
||||
* structure parameter. It is the responsibility of the Message
|
||||
* to dispose of these resources.
|
||||
*
|
||||
* @param cfg Pointer to a #MESSAGE_CONFIG structure.
|
||||
*
|
||||
* @return A non-NULL #MESSAGE_HANDLE for the newly created message, or
|
||||
* NULL upon failure.
|
||||
*/
|
||||
extern MESSAGE_HANDLE Message_Create(const MESSAGE_CONFIG* cfg);
|
||||
|
||||
/** @brief Creates a new reference counted message from a byte array
|
||||
* containing the serialized form of a message.
|
||||
*
|
||||
* @details The newly created message shall have all the properties of the
|
||||
* original message and the same content.
|
||||
*
|
||||
* @param source Pointer to a byte array.
|
||||
* @param size size in bytes of the array
|
||||
*
|
||||
* @return A non-NULL #MESSAGE_HANDLE for the newly created message, or
|
||||
* NULL upon failure.
|
||||
*/
|
||||
extern MESSAGE_HANDLE Message_CreateFromByteArray(const unsigned char* source, int32_t size);
|
||||
|
||||
/** @brief Creates a byte array representation of a MESSAGE_HANDLE.
|
||||
*
|
||||
* @details The byte array created can be used with function
|
||||
* #Message_CreateFromByteArray to reproduce the message. If buffer
|
||||
* is not set, this function will return the serialization size.
|
||||
*
|
||||
* @param messageHandle A #MESSAGE_HANDLE. Must not be NULL.
|
||||
* @param buf A pointer to a byte array in memory, or NULL.
|
||||
* @param size An int32_t that specifies the size of buf.
|
||||
*
|
||||
* @return An int32_t that specifies the size of the serialized message
|
||||
* written when "buf" is not NULL. If "buf" is NULL, returns the
|
||||
* size required for a full successful serialization. Returns a
|
||||
* negative value when an error occurs.
|
||||
*/
|
||||
extern int32_t Message_ToByteArray(MESSAGE_HANDLE messageHandle, unsigned char* buf, int32_t size);
|
||||
|
||||
/** @brief Creates a new message from a @c CONSTBUFFER source and
|
||||
* @c MAP_HANDLE.
|
||||
*
|
||||
* @details This function will create a new message its own @c CONSTBUFFER
|
||||
* and @c ConstMap with copies of the @c source and @c
|
||||
* sourceProperties contained within the #MESSAGE_CONFIG structure
|
||||
* parameter. The message will be created with the reference count
|
||||
* initialized to 1. It is the responsibility of the Message to
|
||||
* dispose of these resources.
|
||||
*
|
||||
* @param cfg Pointer to a #MESSAGE_BUFFER_CONFIG structure.
|
||||
*
|
||||
* @return A non-NULL #MESSAGE_HANDLE for the newly created message, or
|
||||
* @c NULL upon failure.
|
||||
*/
|
||||
extern MESSAGE_HANDLE Message_CreateFromBuffer(const MESSAGE_BUFFER_CONFIG* cfg);
|
||||
|
||||
/** @brief Creates a clone of the message.
|
||||
*
|
||||
* @details Since messages are immutable, this function only increments the
|
||||
* inner reference count.
|
||||
*
|
||||
* @param message The #MESSAGE_HANDLE that will be cloned.
|
||||
*
|
||||
* @return A non-NULL #MESSAGE_HANDLE cloned from @c message, or @c NULL
|
||||
* upon failure.
|
||||
*/
|
||||
extern MESSAGE_HANDLE Message_Clone(MESSAGE_HANDLE message);
|
||||
|
||||
/** @brief Gets the properties of a message.
|
||||
*
|
||||
* @details The returned @c CONSTMAP handle should be destroyed when no
|
||||
* longer needed.
|
||||
*
|
||||
* @param message The #MESSAGE_HANDLE from which properties will be
|
||||
* fetched.
|
||||
*
|
||||
* @return A non-NULL @c CONSTMAP_HANDLE representing the properties of the
|
||||
* message, or @c NULL upon failure.
|
||||
*
|
||||
*/
|
||||
extern CONSTMAP_HANDLE Message_GetProperties(MESSAGE_HANDLE message);
|
||||
|
||||
/** @brief Gets the content of a message.
|
||||
*
|
||||
* @details The returned @c CONSTBUFFER need not be freed by the caller.
|
||||
*
|
||||
* @param message The #MESSAGE_HANDLE from which the content will be
|
||||
* fetched.
|
||||
*
|
||||
* @return A non-NULL pointer to a @c CONSTBUFFER representing the content
|
||||
* of the message, or @c NULL upon failure.
|
||||
*/
|
||||
extern const CONSTBUFFER* Message_GetContent(MESSAGE_HANDLE message);
|
||||
|
||||
/** @brief Gets the @c CONSTBUFFER handle that may be used to access the
|
||||
* message content.
|
||||
*
|
||||
* @details This handle must be destroyed when no longer needed.
|
||||
*
|
||||
* @param message The #MESSAGE_HANDLE from which the content will be
|
||||
* fetched.
|
||||
*
|
||||
* @return A non-NULL @c CONSTBUFFER_HANDLE representing the message
|
||||
* content, or @c NULL upon failure.
|
||||
*/
|
||||
extern CONSTBUFFER_HANDLE Message_GetContentHandle(MESSAGE_HANDLE message);
|
||||
|
||||
/** @brief Disposes of resources allocated by the message.
|
||||
*
|
||||
* @param message The #MESSAGE_HANDLE to be destroyed.
|
||||
*/
|
||||
extern void Message_Destroy(MESSAGE_HANDLE message);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#else
|
||||
#endif
|
||||
|
||||
#endif /*MESSAGE_H*/
|
207
inc/module.h
207
inc/module.h
|
@ -1,207 +0,0 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
/** @file module.h
|
||||
* @brief Interface for modules which communicate with other modules via
|
||||
* a message broker.
|
||||
*
|
||||
* @details Every module associated with the message broker must implement
|
||||
* this interface.
|
||||
* A module can only belong to one message broker; a message broker
|
||||
* may have many modules associated with it.
|
||||
*
|
||||
* Every module library exports a function (Module_GetApi) that
|
||||
* returns a pointer to the #MODULE_API structure.
|
||||
*/
|
||||
|
||||
#ifndef MODULE_H
|
||||
#define MODULE_H
|
||||
|
||||
/** @brief Encapsulates a module's handle and a cached copy of its interface.
|
||||
*/
|
||||
typedef struct MODULE_TAG MODULE;
|
||||
|
||||
/** @brief Represents a module instance. */
|
||||
typedef void* MODULE_HANDLE;
|
||||
|
||||
/** @brief Provides access to a module's interface. */
|
||||
typedef struct MODULE_API_TAG MODULE_API;
|
||||
|
||||
#include "azure_c_shared_utility/macro_utils.h"
|
||||
#include "broker.h"
|
||||
#include "message.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/** @brief Structure used to represent/abstract the idea of a module. May
|
||||
* contain Handle/FxnPtrs or an interface ptr or some unforseen
|
||||
* representation.
|
||||
*/
|
||||
struct MODULE_TAG
|
||||
{
|
||||
/** @brief Struct containing function pointers */
|
||||
const MODULE_API* module_apis;
|
||||
/** @brief HANDLE for module. */
|
||||
MODULE_HANDLE module_handle;
|
||||
};
|
||||
|
||||
/** @brief Translates module configuration from a JSON string to a
|
||||
* module specific data structure.
|
||||
*
|
||||
* @details This function must be implemented by modules that support
|
||||
* configuration options.
|
||||
*
|
||||
* @param configuration A JSON string which describes any needed
|
||||
* configuration to create this module.
|
||||
*
|
||||
* @return A void pointer containing a parsed representation of the
|
||||
* module's configuration.
|
||||
*/
|
||||
typedef void*(*pfModule_ParseConfigurationFromJson)(const char* configuration);
|
||||
|
||||
/** @brief Frees the configuration object returned by the
|
||||
* ParseConfigurationFromJson function.
|
||||
*
|
||||
* @details This function must be implemented by modules that support
|
||||
* configuration options.
|
||||
*
|
||||
* @param configuration A void pointer containing a parsed representation
|
||||
* of the module's configuration.
|
||||
*/
|
||||
typedef void(*pfModule_FreeConfiguration)(void* configuration);
|
||||
|
||||
/** @brief Creates an instance of a module.
|
||||
*
|
||||
* @details This function must be implemented.
|
||||
*
|
||||
* @param broker The #BROKER_HANDLE to which this module
|
||||
* will publish messages.
|
||||
* @param configuration A pointer to the user-defined configuration
|
||||
* structure for this module.
|
||||
*
|
||||
* @return A non-NULL #MODULE_HANDLE upon success, otherwise @c NULL.
|
||||
*/
|
||||
typedef MODULE_HANDLE(*pfModule_Create)(BROKER_HANDLE broker, const void* configuration);
|
||||
|
||||
/** @brief Disposes of the resources managed by this module.
|
||||
*
|
||||
* @details This function must be implemented.
|
||||
*
|
||||
* @param moduleHandle The #MODULE_HANDLE of the module to be
|
||||
* destroyed.
|
||||
*/
|
||||
typedef void(*pfModule_Destroy)(MODULE_HANDLE moduleHandle);
|
||||
|
||||
/** @brief Receives a message from the broker.
|
||||
*
|
||||
* @details This function must be implemented.
|
||||
*
|
||||
* @param moduleHandle The #MODULE_HANDLE of the module receiving
|
||||
* the message.
|
||||
* @param messageHandle The #MESSAGE_HANDLE of the message being
|
||||
* sent to the module.
|
||||
*/
|
||||
typedef void(*pfModule_Receive)(MODULE_HANDLE moduleHandle, MESSAGE_HANDLE messageHandle);
|
||||
|
||||
/** @brief Signals to the module that the broker is ready to send and
|
||||
* receive messages.
|
||||
*
|
||||
* @details This function is optional, but recommended. Messaging in
|
||||
* the gateway is more predictable when modules delay
|
||||
* publishing until after this function is called.
|
||||
*
|
||||
* @param moduleHandle The target module's #MODULE_HANDLE.
|
||||
*/
|
||||
typedef void(*pfModule_Start)(MODULE_HANDLE moduleHandle);
|
||||
|
||||
/** @brief Module API version. */
|
||||
typedef enum MODULE_API_VERSION_TAG
|
||||
{
|
||||
MODULE_API_VERSION_1
|
||||
} MODULE_API_VERSION;
|
||||
|
||||
/** @brief Current gateway module API version */
|
||||
static const MODULE_API_VERSION Module_ApiGatewayVersion = MODULE_API_VERSION_1;
|
||||
|
||||
/** @brief Structure returned by ::Module_GetApi containing the API
|
||||
* version. By convention, the module returns a compound structure
|
||||
* containing this structure and a function table. The version
|
||||
* determines the function table attached to the structure.
|
||||
*/
|
||||
struct MODULE_API_TAG
|
||||
{
|
||||
/** @brief The version of the MODULES_API, shall always be the first
|
||||
* element of this structure
|
||||
*/
|
||||
MODULE_API_VERSION version;
|
||||
};
|
||||
|
||||
/** @brief The module interface, version 1. An instance of this struct
|
||||
* contains function pointers to module-specific implementations of
|
||||
* the interface.
|
||||
*/
|
||||
typedef struct MODULE_API_1_TAG
|
||||
{
|
||||
/** @brief Always the first element on a Module's API*/
|
||||
MODULE_API base;
|
||||
|
||||
/** @brief Function pointer to the #Module_ParseConfigurationFromJson
|
||||
* function. */
|
||||
pfModule_ParseConfigurationFromJson Module_ParseConfigurationFromJson;
|
||||
|
||||
/** @brief Function pointer to the #Module_FreeConfiguration
|
||||
* function. */
|
||||
pfModule_FreeConfiguration Module_FreeConfiguration;
|
||||
|
||||
/** @brief Function pointer to the #Module_Create function. */
|
||||
pfModule_Create Module_Create;
|
||||
|
||||
/** @brief Function pointer to the #Module_Destroy function. */
|
||||
pfModule_Destroy Module_Destroy;
|
||||
|
||||
/** @brief Function pointer to the #Module_Receive function. */
|
||||
pfModule_Receive Module_Receive;
|
||||
|
||||
/** @brief Function pointer to the #Module_Start function (optional).
|
||||
*/
|
||||
pfModule_Start Module_Start;
|
||||
} MODULE_API_1;
|
||||
|
||||
/** @brief This is the only function exported by a module. Using the
|
||||
* exported function, the caller learns the functions for the
|
||||
* particular module.
|
||||
* @param gateway_api_version The current API version of the gateway.
|
||||
*
|
||||
* @return NULL in failure, MODULE_API* pointer on success.
|
||||
*/
|
||||
typedef const MODULE_API* (*pfModule_GetApi)(MODULE_API_VERSION gateway_api_version);
|
||||
|
||||
/** @brief Returns the module APIS name.*/
|
||||
#define MODULE_GETAPI_NAME ("Module_GetApi")
|
||||
|
||||
#ifdef _WIN32
|
||||
#define MODULE_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define MODULE_EXPORT
|
||||
#endif // _WIN32
|
||||
|
||||
/** @brief Returns a unique name for pfModule_GetApi that is used when
|
||||
* the module is statically linked.
|
||||
*/
|
||||
#define MODULE_STATIC_GETAPI(MODULE_NAME) C2(Module_GetApi_, MODULE_NAME)
|
||||
|
||||
/** @brief This is the only function exported by a module under a "by
|
||||
* convention" name. Using the exported function, the caller learns
|
||||
* the functions for the particular module.
|
||||
*/
|
||||
MODULE_EXPORT const MODULE_API* Module_GetApi(MODULE_API_VERSION gateway_api_version);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // MODULE_H
|
|
@ -1,243 +0,0 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
/** @file module_loader.h
|
||||
* @brief Definition of the functions and structures that must be
|
||||
* implemented by a gateway module loader.
|
||||
*
|
||||
* @details A gateway module loader library must make available to the
|
||||
* gateway application (e.g. via a function) an instance of the
|
||||
* #MODULE_LOADER_API structure. This structure must contain valid
|
||||
* pointers to functions that can be invoked by the gateway to load
|
||||
* and unload a gateway module, and get its interface.
|
||||
*/
|
||||
|
||||
#ifndef MODULE_LOADER_H
|
||||
#define MODULE_LOADER_H
|
||||
|
||||
#include "azure_c_shared_utility/macro_utils.h"
|
||||
#include "azure_c_shared_utility/umock_c_prod.h"
|
||||
|
||||
#include "module.h"
|
||||
#include "parson.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/** @brief handle for a module library */
|
||||
typedef void* MODULE_LIBRARY_HANDLE;
|
||||
|
||||
struct MODULE_LOADER_TAG;
|
||||
|
||||
/**
|
||||
* Configuration that is common to all module loaders goes here. The expectation
|
||||
* is that a given module loader will define its own configuration struct but
|
||||
* always have an instance of this struct as the first field.
|
||||
*/
|
||||
typedef struct MODULE_LOADER_BASE_CONFIGURATION_TAG
|
||||
{
|
||||
/** @brief The path to the native binding module.
|
||||
*/
|
||||
STRING_HANDLE binding_path;
|
||||
} MODULE_LOADER_BASE_CONFIGURATION;
|
||||
|
||||
typedef MODULE_LIBRARY_HANDLE(*pfModuleLoader_Load)(const struct MODULE_LOADER_TAG* loader, const void* entrypoint);
|
||||
typedef void(*pfModuleLoader_Unload)(const struct MODULE_LOADER_TAG* loader, MODULE_LIBRARY_HANDLE handle);
|
||||
typedef const MODULE_API*(*pfModuleLoader_GetApi)(const struct MODULE_LOADER_TAG* loader, MODULE_LIBRARY_HANDLE handle);
|
||||
|
||||
typedef void*(*pfModuleLoader_ParseEntrypointFromJson)(const struct MODULE_LOADER_TAG* loader, const JSON_Value* json);
|
||||
typedef void(*pfModuleLoader_FreeEntrypoint)(const struct MODULE_LOADER_TAG* loader, void* entrypoint);
|
||||
|
||||
typedef MODULE_LOADER_BASE_CONFIGURATION*(*pfModuleLoader_ParseConfigurationFromJson)(const struct MODULE_LOADER_TAG* loader, const JSON_Value* json);
|
||||
typedef void(*pfModuleLoader_FreeConfiguration)(const struct MODULE_LOADER_TAG* loader, MODULE_LOADER_BASE_CONFIGURATION* configuration);
|
||||
|
||||
typedef void*(*pfModuleLoader_BuildModuleConfiguration)(const struct MODULE_LOADER_TAG* loader, const void* entrypoint, const void* module_configuration);
|
||||
typedef void(*pfModuleLoader_FreeModuleConfiguration)(const struct MODULE_LOADER_TAG* loader, const void* module_configuration);
|
||||
|
||||
/** @brief Function table for loading modules into a gateway */
|
||||
typedef struct MODULE_LOADER_API_TAG
|
||||
{
|
||||
/** @brief Load function, loads module for gateway, returns a valid handle
|
||||
* on success */
|
||||
pfModuleLoader_Load Load;
|
||||
|
||||
/** @brief Unload function, unloads the library from the gateway */
|
||||
pfModuleLoader_Unload Unload;
|
||||
|
||||
/** @brief GetApi function, gets the MODULE_API for the loaded module */
|
||||
pfModuleLoader_GetApi GetApi;
|
||||
|
||||
/** @brief ParseEntrypointFromJson function, parses entrypoint information
|
||||
provided in JSON form and returns a pointer to a struct that the module will
|
||||
be able to use */
|
||||
pfModuleLoader_ParseEntrypointFromJson ParseEntrypointFromJson;
|
||||
/** @brief FreeEntrypoint function, frees the memory returned by
|
||||
ParseEntryPoint */
|
||||
pfModuleLoader_FreeEntrypoint FreeEntrypoint;
|
||||
|
||||
/** @brief ParseConfigurationFromJson function, parses module loader
|
||||
configuration information provided in JSON form and returns a pointer to a
|
||||
struct that the module loader will be able to use */
|
||||
pfModuleLoader_ParseConfigurationFromJson ParseConfigurationFromJson;
|
||||
/** @brief FreeEntrypoint function, frees the memory returned by
|
||||
ParseConfigurationFromJson */
|
||||
pfModuleLoader_FreeConfiguration FreeConfiguration;
|
||||
|
||||
/** @brief ParseConfigurationFromJson function, responsible for merging
|
||||
entrypoint data and data from module configuration into a struct that
|
||||
language binding modules expect*/
|
||||
pfModuleLoader_BuildModuleConfiguration BuildModuleConfiguration;
|
||||
/** @brief FreeEntrypoint function, frees the memory returned by
|
||||
BuildModuleConfiguration */
|
||||
pfModuleLoader_FreeModuleConfiguration FreeModuleConfiguration;
|
||||
} MODULE_LOADER_API;
|
||||
|
||||
/**
|
||||
* @brief Module loader type.
|
||||
*/
|
||||
|
||||
#define MODULE_LOADER_TYPE_VALUES \
|
||||
UNKNOWN, \
|
||||
NATIVE, \
|
||||
JAVA, \
|
||||
DOTNET, \
|
||||
NODEJS
|
||||
|
||||
/**
|
||||
* @brief Enumeration listing all supported module loaders
|
||||
*/
|
||||
DEFINE_ENUM(MODULE_LOADER_TYPE, MODULE_LOADER_TYPE_VALUES);
|
||||
|
||||
|
||||
/**
|
||||
* The Module Loader.
|
||||
*/
|
||||
typedef struct MODULE_LOADER_TAG
|
||||
{
|
||||
/** @brief The module loader type from the MODULE_LOADER_TYPE enumeration. */
|
||||
MODULE_LOADER_TYPE type;
|
||||
|
||||
/** @brief The module loader's name used to reference this loader when
|
||||
* using JSON to configure a gateway. */
|
||||
const char* name;
|
||||
|
||||
/** @brief The module loader's' configuration. For example the Java
|
||||
* language binding loader might store JVM runtime options here. */
|
||||
MODULE_LOADER_BASE_CONFIGURATION* configuration;
|
||||
|
||||
/** @brief The module loader's' API implementation. */
|
||||
MODULE_LOADER_API* api;
|
||||
} MODULE_LOADER;
|
||||
|
||||
#define MODULE_LOADER_RESULT_VALUES \
|
||||
MODULE_LOADER_SUCCESS, \
|
||||
MODULE_LOADER_ERROR
|
||||
|
||||
/**
|
||||
* @brief Enumeration describing the result of module loader APIs
|
||||
*/
|
||||
DEFINE_ENUM(MODULE_LOADER_RESULT, MODULE_LOADER_RESULT_VALUES);
|
||||
|
||||
/**
|
||||
* @brief Utility function for parsing a JSON object that has a property called
|
||||
* "binding.path" into a MODULE_LOADER_BASE_CONFIGURATION instance.
|
||||
*/
|
||||
MOCKABLE_FUNCTION(, MODULE_LOADER_RESULT, ModuleLoader_ParseBaseConfigurationFromJson,
|
||||
MODULE_LOADER_BASE_CONFIGURATION*, configuration,
|
||||
const JSON_Value*, json
|
||||
);
|
||||
|
||||
/**
|
||||
* @brief Utility function for freeing a MODULE_LOADER_BASE_CONFIGURATION*
|
||||
* instance from a previous call to
|
||||
* ModuleLoader_ParseBaseConfigurationFromJson.
|
||||
*/
|
||||
MOCKABLE_FUNCTION(, void, ModuleLoader_FreeBaseConfiguration, MODULE_LOADER_BASE_CONFIGURATION*, configuration);
|
||||
|
||||
/**
|
||||
* @brief This function creates the default set of module loaders that the
|
||||
* gateway supports.
|
||||
*/
|
||||
MOCKABLE_FUNCTION(, MODULE_LOADER_RESULT, ModuleLoader_Initialize);
|
||||
|
||||
/**
|
||||
* @brief This function frees resources allocated for tracking module loaders.
|
||||
*/
|
||||
MOCKABLE_FUNCTION(, void, ModuleLoader_Destroy);
|
||||
|
||||
/**
|
||||
* @brief Adds a new module loader to the gateway's collection of module loaders.
|
||||
*/
|
||||
MOCKABLE_FUNCTION(, MODULE_LOADER_RESULT, ModuleLoader_Add, const MODULE_LOADER*, loader);
|
||||
|
||||
/**
|
||||
* @brief Replaces the module loader configuration for the given loader in a
|
||||
* thread-safe manner.
|
||||
*/
|
||||
MOCKABLE_FUNCTION(, MODULE_LOADER_RESULT, ModuleLoader_UpdateConfiguration,
|
||||
MODULE_LOADER*, loader,
|
||||
MODULE_LOADER_BASE_CONFIGURATION*, configuration
|
||||
);
|
||||
|
||||
/**
|
||||
* @brief Searches the module loader collection given the loader's name.
|
||||
*/
|
||||
MOCKABLE_FUNCTION(, MODULE_LOADER*, ModuleLoader_FindByName, const char*, name);
|
||||
|
||||
/**
|
||||
* @brief Given a module loader type, returns the default loader.
|
||||
*/
|
||||
MOCKABLE_FUNCTION(, MODULE_LOADER*, ModuleLoader_GetDefaultLoaderForType, MODULE_LOADER_TYPE, type);
|
||||
|
||||
/**
|
||||
* @brief Given a string representation of a module loader type, returns the
|
||||
* corresponding enum value.
|
||||
*/
|
||||
MOCKABLE_FUNCTION(, MODULE_LOADER_TYPE, ModuleLoader_ParseType, const char*, type);
|
||||
|
||||
/**
|
||||
* @brief Given a module name, determines if it is a default module loader or a
|
||||
* custom one.
|
||||
*/
|
||||
MOCKABLE_FUNCTION(, bool, ModuleLoader_IsDefaultLoader, const char*, name);
|
||||
|
||||
/**
|
||||
* @brief Updates the global loaders array from a JSON that looks like this:
|
||||
*
|
||||
* "loaders": [
|
||||
* {
|
||||
* "type": "node",
|
||||
* "name": "node",
|
||||
* "configuration": {
|
||||
* "binding.path": "./bin/libnode_binding.so"
|
||||
* }
|
||||
* },
|
||||
* {
|
||||
* "type": "java",
|
||||
* "name": "java",
|
||||
* "configuration": {
|
||||
* "jvm.options": {
|
||||
* "memory": 1073741824
|
||||
* },
|
||||
* "gateway.class.path": "./bin/gateway.jar",
|
||||
* "binding.path": "./bin/libjava_binding.so"
|
||||
* }
|
||||
* },
|
||||
* {
|
||||
* "type": "dotnet",
|
||||
* "name": "dotnet",
|
||||
* "configuration": {
|
||||
* "binding.path": "./bin/libdotnet_binding.so"
|
||||
* }
|
||||
* }
|
||||
* ]
|
||||
*/
|
||||
MOCKABLE_FUNCTION(, MODULE_LOADER_RESULT, ModuleLoader_InitializeFromJson, const JSON_Value*, loaders);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // MODULE_LOADER_H
|
231
inc/parson.h
231
inc/parson.h
|
@ -1,231 +0,0 @@
|
|||
/*
|
||||
Parson ( http://kgabis.github.com/parson/ )
|
||||
Copyright (c) 2012 - 2016 Krzysztof Gabis
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef parson_parson_h
|
||||
#define parson_parson_h
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include <stddef.h> /* size_t */
|
||||
|
||||
/* Types and enums */
|
||||
typedef struct json_object_t JSON_Object;
|
||||
typedef struct json_array_t JSON_Array;
|
||||
typedef struct json_value_t JSON_Value;
|
||||
|
||||
enum json_value_type {
|
||||
JSONError = -1,
|
||||
JSONNull = 1,
|
||||
JSONString = 2,
|
||||
JSONNumber = 3,
|
||||
JSONObject = 4,
|
||||
JSONArray = 5,
|
||||
JSONBoolean = 6
|
||||
};
|
||||
typedef int JSON_Value_Type;
|
||||
|
||||
enum json_result_t {
|
||||
JSONSuccess = 0,
|
||||
JSONFailure = -1
|
||||
};
|
||||
typedef int JSON_Status;
|
||||
|
||||
typedef void * (*JSON_Malloc_Function)(size_t);
|
||||
typedef void (*JSON_Free_Function)(void *);
|
||||
|
||||
/* Call only once, before calling any other function from parson API. If not called, malloc and free
|
||||
from stdlib will be used for all allocations */
|
||||
void json_set_allocation_functions(JSON_Malloc_Function malloc_fun, JSON_Free_Function free_fun);
|
||||
|
||||
/* Parses first JSON value in a file, returns NULL in case of error */
|
||||
JSON_Value * json_parse_file(const char *filename);
|
||||
|
||||
/* Parses first JSON value in a file and ignores comments (/ * * / and //),
|
||||
returns NULL in case of error */
|
||||
JSON_Value * json_parse_file_with_comments(const char *filename);
|
||||
|
||||
/* Parses first JSON value in a string, returns NULL in case of error */
|
||||
JSON_Value * json_parse_string(const char *string);
|
||||
|
||||
/* Parses first JSON value in a string and ignores comments (/ * * / and //),
|
||||
returns NULL in case of error */
|
||||
JSON_Value * json_parse_string_with_comments(const char *string);
|
||||
|
||||
/* Serialization */
|
||||
size_t json_serialization_size(const JSON_Value *value); /* returns 0 on fail */
|
||||
JSON_Status json_serialize_to_buffer(const JSON_Value *value, char *buf, size_t buf_size_in_bytes);
|
||||
JSON_Status json_serialize_to_file(const JSON_Value *value, const char *filename);
|
||||
char * json_serialize_to_string(const JSON_Value *value);
|
||||
|
||||
/* Pretty serialization */
|
||||
size_t json_serialization_size_pretty(const JSON_Value *value); /* returns 0 on fail */
|
||||
JSON_Status json_serialize_to_buffer_pretty(const JSON_Value *value, char *buf, size_t buf_size_in_bytes);
|
||||
JSON_Status json_serialize_to_file_pretty(const JSON_Value *value, const char *filename);
|
||||
char * json_serialize_to_string_pretty(const JSON_Value *value);
|
||||
|
||||
void json_free_serialized_string(char *string); /* frees string from json_serialize_to_string and json_serialize_to_string_pretty */
|
||||
|
||||
/* Comparing */
|
||||
int json_value_equals(const JSON_Value *a, const JSON_Value *b);
|
||||
|
||||
/* Validation
|
||||
This is *NOT* JSON Schema. It validates json by checking if object have identically
|
||||
named fields with matching types.
|
||||
For example schema {"name":"", "age":0} will validate
|
||||
{"name":"Joe", "age":25} and {"name":"Joe", "age":25, "gender":"m"},
|
||||
but not {"name":"Joe"} or {"name":"Joe", "age":"Cucumber"}.
|
||||
In case of arrays, only first value in schema is checked against all values in tested array.
|
||||
Empty objects ({}) validate all objects, empty arrays ([]) validate all arrays,
|
||||
null validates values of every type.
|
||||
*/
|
||||
JSON_Status json_validate(const JSON_Value *schema, const JSON_Value *value);
|
||||
|
||||
/*
|
||||
* JSON Object
|
||||
*/
|
||||
JSON_Value * json_object_get_value (const JSON_Object *object, const char *name);
|
||||
const char * json_object_get_string (const JSON_Object *object, const char *name);
|
||||
JSON_Object * json_object_get_object (const JSON_Object *object, const char *name);
|
||||
JSON_Array * json_object_get_array (const JSON_Object *object, const char *name);
|
||||
double json_object_get_number (const JSON_Object *object, const char *name); /* returns 0 on fail */
|
||||
int json_object_get_boolean(const JSON_Object *object, const char *name); /* returns -1 on fail */
|
||||
|
||||
/* dotget functions enable addressing values with dot notation in nested objects,
|
||||
just like in structs or c++/java/c# objects (e.g. objectA.objectB.value).
|
||||
Because valid names in JSON can contain dots, some values may be inaccessible
|
||||
this way. */
|
||||
JSON_Value * json_object_dotget_value (const JSON_Object *object, const char *name);
|
||||
const char * json_object_dotget_string (const JSON_Object *object, const char *name);
|
||||
JSON_Object * json_object_dotget_object (const JSON_Object *object, const char *name);
|
||||
JSON_Array * json_object_dotget_array (const JSON_Object *object, const char *name);
|
||||
double json_object_dotget_number (const JSON_Object *object, const char *name); /* returns 0 on fail */
|
||||
int json_object_dotget_boolean(const JSON_Object *object, const char *name); /* returns -1 on fail */
|
||||
|
||||
/* Functions to get available names */
|
||||
size_t json_object_get_count (const JSON_Object *object);
|
||||
const char * json_object_get_name (const JSON_Object *object, size_t index);
|
||||
JSON_Value * json_object_get_value_at(const JSON_Object *object, size_t index);
|
||||
|
||||
/* Functions to check if object has a value with a specific name. Returned value is 1 if object has
|
||||
* a value and 0 if it doesn't. dothas functions behave exactly like dotget functions. */
|
||||
int json_object_has_value (const JSON_Object *object, const char *name);
|
||||
int json_object_has_value_of_type(const JSON_Object *object, const char *name, JSON_Value_Type type);
|
||||
|
||||
int json_object_dothas_value (const JSON_Object *object, const char *name);
|
||||
int json_object_dothas_value_of_type(const JSON_Object *object, const char *name, JSON_Value_Type type);
|
||||
|
||||
/* Creates new name-value pair or frees and replaces old value with a new one.
|
||||
* json_object_set_value does not copy passed value so it shouldn't be freed afterwards. */
|
||||
JSON_Status json_object_set_value(JSON_Object *object, const char *name, JSON_Value *value);
|
||||
JSON_Status json_object_set_string(JSON_Object *object, const char *name, const char *string);
|
||||
JSON_Status json_object_set_number(JSON_Object *object, const char *name, double number);
|
||||
JSON_Status json_object_set_boolean(JSON_Object *object, const char *name, int boolean);
|
||||
JSON_Status json_object_set_null(JSON_Object *object, const char *name);
|
||||
|
||||
/* Works like dotget functions, but creates whole hierarchy if necessary.
|
||||
* json_object_dotset_value does not copy passed value so it shouldn't be freed afterwards. */
|
||||
JSON_Status json_object_dotset_value(JSON_Object *object, const char *name, JSON_Value *value);
|
||||
JSON_Status json_object_dotset_string(JSON_Object *object, const char *name, const char *string);
|
||||
JSON_Status json_object_dotset_number(JSON_Object *object, const char *name, double number);
|
||||
JSON_Status json_object_dotset_boolean(JSON_Object *object, const char *name, int boolean);
|
||||
JSON_Status json_object_dotset_null(JSON_Object *object, const char *name);
|
||||
|
||||
/* Frees and removes name-value pair */
|
||||
JSON_Status json_object_remove(JSON_Object *object, const char *name);
|
||||
|
||||
/* Works like dotget function, but removes name-value pair only on exact match. */
|
||||
JSON_Status json_object_dotremove(JSON_Object *object, const char *key);
|
||||
|
||||
/* Removes all name-value pairs in object */
|
||||
JSON_Status json_object_clear(JSON_Object *object);
|
||||
|
||||
/*
|
||||
*JSON Array
|
||||
*/
|
||||
JSON_Value * json_array_get_value (const JSON_Array *array, size_t index);
|
||||
const char * json_array_get_string (const JSON_Array *array, size_t index);
|
||||
JSON_Object * json_array_get_object (const JSON_Array *array, size_t index);
|
||||
JSON_Array * json_array_get_array (const JSON_Array *array, size_t index);
|
||||
double json_array_get_number (const JSON_Array *array, size_t index); /* returns 0 on fail */
|
||||
int json_array_get_boolean(const JSON_Array *array, size_t index); /* returns -1 on fail */
|
||||
size_t json_array_get_count (const JSON_Array *array);
|
||||
|
||||
/* Frees and removes value at given index, does nothing and returns JSONFailure if index doesn't exist.
|
||||
* Order of values in array may change during execution. */
|
||||
JSON_Status json_array_remove(JSON_Array *array, size_t i);
|
||||
|
||||
/* Frees and removes from array value at given index and replaces it with given one.
|
||||
* Does nothing and returns JSONFailure if index doesn't exist.
|
||||
* json_array_replace_value does not copy passed value so it shouldn't be freed afterwards. */
|
||||
JSON_Status json_array_replace_value(JSON_Array *array, size_t i, JSON_Value *value);
|
||||
JSON_Status json_array_replace_string(JSON_Array *array, size_t i, const char* string);
|
||||
JSON_Status json_array_replace_number(JSON_Array *array, size_t i, double number);
|
||||
JSON_Status json_array_replace_boolean(JSON_Array *array, size_t i, int boolean);
|
||||
JSON_Status json_array_replace_null(JSON_Array *array, size_t i);
|
||||
|
||||
/* Frees and removes all values from array */
|
||||
JSON_Status json_array_clear(JSON_Array *array);
|
||||
|
||||
/* Appends new value at the end of array.
|
||||
* json_array_append_value does not copy passed value so it shouldn't be freed afterwards. */
|
||||
JSON_Status json_array_append_value(JSON_Array *array, JSON_Value *value);
|
||||
JSON_Status json_array_append_string(JSON_Array *array, const char *string);
|
||||
JSON_Status json_array_append_number(JSON_Array *array, double number);
|
||||
JSON_Status json_array_append_boolean(JSON_Array *array, int boolean);
|
||||
JSON_Status json_array_append_null(JSON_Array *array);
|
||||
|
||||
/*
|
||||
*JSON Value
|
||||
*/
|
||||
JSON_Value * json_value_init_object (void);
|
||||
JSON_Value * json_value_init_array (void);
|
||||
JSON_Value * json_value_init_string (const char *string); /* copies passed string */
|
||||
JSON_Value * json_value_init_number (double number);
|
||||
JSON_Value * json_value_init_boolean(int boolean);
|
||||
JSON_Value * json_value_init_null (void);
|
||||
JSON_Value * json_value_deep_copy (const JSON_Value *value);
|
||||
void json_value_free (JSON_Value *value);
|
||||
|
||||
JSON_Value_Type json_value_get_type (const JSON_Value *value);
|
||||
JSON_Object * json_value_get_object (const JSON_Value *value);
|
||||
JSON_Array * json_value_get_array (const JSON_Value *value);
|
||||
const char * json_value_get_string (const JSON_Value *value);
|
||||
double json_value_get_number (const JSON_Value *value);
|
||||
int json_value_get_boolean(const JSON_Value *value);
|
||||
|
||||
/* Same as above, but shorter */
|
||||
JSON_Value_Type json_type (const JSON_Value *value);
|
||||
JSON_Object * json_object (const JSON_Value *value);
|
||||
JSON_Array * json_array (const JSON_Value *value);
|
||||
const char * json_string (const JSON_Value *value);
|
||||
double json_number (const JSON_Value *value);
|
||||
int json_boolean(const JSON_Value *value);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,5 +0,0 @@
|
|||
What you need:
|
||||
aziotsharedutil.lib
|
||||
gateway.lib
|
||||
nanomsg.lib
|
||||
parson.lib
|
|
@ -1,7 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Azure.IoT.Gateway.SDK.Net" version="2017.1.13.2" targetFramework="net46" />
|
||||
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net461" />
|
||||
<package id="OPCFoundation.NetStandard.Opc.Ua.Core" version="0.1.0" targetFramework="net46" />
|
||||
<package id="OPCFoundation.NetStandard.Opc.Ua.SDK" version="0.1.0" targetFramework="net46" />
|
||||
<package id="OPCFoundation.NetStandard.Opc.Ua.Core" version="0.1.1" targetFramework="net46" />
|
||||
<package id="OPCFoundation.NetStandard.Opc.Ua.SDK" version="0.1.1" targetFramework="net46" />
|
||||
<package id="Portable.BouncyCastle" version="1.8.1.2" targetFramework="net46" />
|
||||
</packages>
|
Загрузка…
Ссылка в новой задаче