Skip to content

Commit

Permalink
[IMemoryMonitor] Update with JSON-RPC interface (#411)
Browse files Browse the repository at this point in the history
* Add the IMemoryMonitor interface

* Adjust the Windows project files

* Update params to be present in the md
  • Loading branch information
VeithMetro authored Feb 11, 2025
1 parent 12487a4 commit 0a4746d
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 5 deletions.
16 changes: 15 additions & 1 deletion definitions/Definitions.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
<ClCompile Include="..\interfaces\json\JsonEnum_InputSwitch.cpp" />
<ClCompile Include="..\interfaces\json\JsonEnum_IOConnector.cpp" />
<ClCompile Include="..\interfaces\json\JsonEnum_Math.cpp" />
<ClCompile Include="..\interfaces\json\JsonEnum_MemoryMonitor.cpp" />
<ClCompile Include="..\interfaces\json\JsonEnum_MessageControl.cpp" />
<ClCompile Include="..\interfaces\json\JsonEnum_Messenger.cpp" />
<ClCompile Include="..\interfaces\json\JsonEnum_Monitor.cpp" />
<ClCompile Include="..\interfaces\json\JsonEnum_Netflix.cpp" />
<ClCompile Include="..\interfaces\json\JsonEnum_NetworkControl.cpp" />
<ClCompile Include="..\interfaces\json\JsonEnum_OCDM.cpp" />
Expand Down Expand Up @@ -77,6 +77,20 @@
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">python "$(ToolPath)\JsonGenerator\JsonGenerator.py" -I "$(FrameworkPath)\" -I "$(ProjectDir)\" --case-convention legacy --keep-empty -c -j "$(ProjectDir)../interfaces" -o "$(ProjectDir)../interfaces/json" "%(FullPath)" --force</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">python "$(ToolPath)\JsonGenerator\JsonGenerator.py" -I "$(FrameworkPath)\" -I "$(ProjectDir)\" --case-convention legacy --keep-empty -c -j "$(ProjectDir)../interfaces" -o "$(ProjectDir)../interfaces/json" "%(FullPath)" --force</Command>
</CustomBuild>
<CustomBuild Include="..\interfaces\IMemoryMonitor.h">
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">python "$(ToolPath)\JsonGenerator\JsonGenerator.py" -I "$(FrameworkPath)\" -I "$(ProjectDir)\" --keep-empty --case-convention legacy -c -j "$(ProjectDir)../interfaces" -o "$(ProjectDir)../interfaces/json" "%(FullPath)" --force</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">python "$(ToolPath)\JsonGenerator\JsonGenerator.py" -I "$(FrameworkPath)\" -I "$(ProjectDir)\" --keep-empty --case-convention legacy -c -j "$(ProjectDir)../interfaces" -o "$(ProjectDir)../interfaces/json" "%(FullPath)" --force</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">python "$(ToolPath)\JsonGenerator\JsonGenerator.py" -I "$(FrameworkPath)\" -I "$(ProjectDir)\" --keep-empty --case-convention legacy -c -j "$(ProjectDir)../interfaces" -o "$(ProjectDir)../interfaces/json" "%(FullPath)" --force</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">python "$(ToolPath)\JsonGenerator\JsonGenerator.py" -I "$(FrameworkPath)\" -I "$(ProjectDir)\" --keep-empty --case-convention legacy -c -j "$(ProjectDir)../interfaces" -o "$(ProjectDir)../interfaces/json" "%(FullPath)" --force</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(ProjectDir)../interfaces/json/JMemoryMonitor.h</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(ProjectDir)../interfaces/json/JMemoryMonitor.h</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(ProjectDir)../interfaces/json/JMemoryMonitor.h</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(ProjectDir)../interfaces/json/JMemoryMonitor.h</Outputs>
<OutputItemType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">ClInclude</OutputItemType>
<OutputItemType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">ClInclude</OutputItemType>
<OutputItemType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">ClInclude</OutputItemType>
<OutputItemType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">ClInclude</OutputItemType>
</CustomBuild>
<CustomBuild Include="..\interfaces\ILocationSync.h">
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">python "$(ToolPath)\JsonGenerator\JsonGenerator.py" -I "$(FrameworkPath)\" -I "$(ProjectDir)\" --keep-empty --case-convention legacy -c -j "$(ProjectDir)../interfaces" -o "$(ProjectDir)../interfaces/json" "%(FullPath)" --force</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">python "$(ToolPath)\JsonGenerator\JsonGenerator.py" -I "$(FrameworkPath)\" -I "$(ProjectDir)\" --keep-empty --case-convention legacy -c -j "$(ProjectDir)../interfaces" -o "$(ProjectDir)../interfaces/json" "%(FullPath)" --force</Command>
Expand Down
9 changes: 6 additions & 3 deletions definitions/Definitions.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@
<ClCompile Include="..\interfaces\json\JsonEnum_Messenger.cpp">
<Filter>Generated Files</Filter>
</ClCompile>
<ClCompile Include="..\interfaces\json\JsonEnum_Monitor.cpp">
<Filter>Generated Files</Filter>
</ClCompile>
<ClCompile Include="..\interfaces\json\JsonEnum_Netflix.cpp">
<Filter>Generated Files</Filter>
</ClCompile>
Expand Down Expand Up @@ -147,6 +144,9 @@
<ClCompile Include="..\interfaces\json\JsonEnum_ZigWave.cpp">
<Filter>Generated Files</Filter>
</ClCompile>
<ClCompile Include="..\interfaces\json\JsonEnum_MemoryMonitor.cpp">
<Filter>Generated Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="definitions.h">
Expand Down Expand Up @@ -279,6 +279,9 @@
<CustomBuild Include="..\interfaces\IMessenger.h">
<Filter>Interfaces</Filter>
</CustomBuild>
<CustomBuild Include="..\interfaces\IMemoryMonitor.h">
<Filter>Interfaces</Filter>
</CustomBuild>
<CustomBuild Include="..\interfaces\ILocationSync.h">
<Filter>Interfaces</Filter>
</CustomBuild>
Expand Down
109 changes: 109 additions & 0 deletions interfaces/IMemoryMonitor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* If not stated otherwise in this file or this component's LICENSE file the
* following copyright and licenses apply:
*
* Copyright 2024 Metrological
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include "Module.h"

// @insert <com/IIteratorType.h>

namespace Thunder {

namespace Exchange {

// @json 1.0.0 @text:legacy_lowercase
struct EXTERNAL IMemoryMonitor : virtual public Core::IUnknown {

enum { ID = ID_MEMORY_MONITOR };

struct Restart {
uint8_t limit /* @brief Maximum number or restarts to be attempted (e.g. 3) */;
uint16_t window /* @brief Time period (in seconds) within which failures must happen for the limit to be considered crossed (e.g. 60) */;
};

struct Measurement {
uint64_t min /* @brief Minimal value measured (e.g. 0) */;
uint64_t max /* @brief Maximal value measured (e.g. 100) */;
uint64_t average /* @brief Average of all measurements (e.g. 50) */;
uint64_t last /* @brief Last measured value (e.g. 100) */;
};

struct Statistics {
Measurement resident /* @brief Resident memory measurement */;
Measurement allocated /* @brief Allocated memory measurement */;
Measurement shared /* @brief Shared memory measurement */;
Measurement process /* @brief Processes measurement */;
bool operational /* @brief Whether the service is up and running (e.g. true) */;
uint32_t count /* @brief Number of measurements (e.g. 100) */;
};

using IStringIterator = RPC::IIteratorType<string, RPC::ID_STRINGITERATOR>;

// @event
struct EXTERNAL INotification : virtual public Core::IUnknown {

enum { ID = ID_MEMORY_MONITOR_NOTIFICATION };

enum action : uint8_t {
DEACTIVATED,
ACTIVATED,
RESTARTING_STOPPED
};

enum reason : uint8_t {
EXCEEDED_MEMORY,
NOT_OPERATIONAL
};

// @brief Signals an action taken by the Monitor
// @param callsign: Callsign of the service the Monitor acted upon (e.g. WebServer)
// @param action: Ation executed by the Monitor on a service (e.g. Deactivate)
// @param reason: Mssage describing the reason the action was taken (e.g. EXCEEDED_MEMORY)
virtual void StatusChanged(const string& callsign, const action action, const Core::OptionalType<reason>& reason) = 0;
};

virtual Core::hresult Register(INotification* const notification) = 0;
virtual Core::hresult Unregister(const INotification* const notification) = 0;

// @property
// @brief Limits of restarting of a service
// @param callsign: Callsign of the service (e.g. WebServer)
// @param restart: Limits of restarts applying to a given service
virtual Core::hresult RestartingLimits(const string& callsign /* @index */, const Restart& restart) = 0;
virtual Core::hresult RestartingLimits(const string& callsign /* @index */, Restart& restart /* @out */) const = 0;

// @property
// @brief List of services watched by the Monitor
// @param observables: List of monitored services
virtual Core::hresult Observables(IStringIterator*& observables /* @out */) const = 0;

// @property
// @brief Memory statistics for a given service
// @param callsign: Callsign of the service (e.g. WebServer)
// @param statistics: Statistics for the requested callsign
virtual Core::hresult MeasurementData(const string& callsign /* @index */, Statistics& statistics /* @out */) const = 0;

// @brief Resets memory statistics for a given service
// @param callsign: Callsign of the service (e.g. WebServer)
virtual Core::hresult ResetStatistics(const string& callsign) = 0;
};

} // namespace Exchange

}
5 changes: 4 additions & 1 deletion interfaces/Ids.h
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,10 @@ namespace Exchange {
ID_SECURITYAGENT = RPC::IDS::ID_EXTERNAL_INTERFACE_OFFSET + 0x550,

ID_LOCATIONSYNC = RPC::IDS::ID_EXTERNAL_INTERFACE_OFFSET + 0x560,
ID_LOCATIONSYNC_NOTIFICATION = ID_LOCATIONSYNC + 1
ID_LOCATIONSYNC_NOTIFICATION = ID_LOCATIONSYNC + 1,

ID_MEMORY_MONITOR = RPC::IDS::ID_EXTERNAL_INTERFACE_OFFSET + 0x570,
ID_MEMORY_MONITOR_NOTIFICATION = ID_MEMORY_MONITOR + 1
};
}
}
1 change: 1 addition & 0 deletions interfaces/Interfaces.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
<ClInclude Include="ILanguageTag.h" />
<ClInclude Include="ILocationSync.h" />
<ClInclude Include="IMemory.h" />
<ClInclude Include="IMemoryMonitor.h" />
<ClInclude Include="IMessageControl.h" />
<ClInclude Include="INetflix.h" />
<ClInclude Include="INetflixSecurity.h" />
Expand Down
3 changes: 3 additions & 0 deletions interfaces/Interfaces.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,9 @@
<ClInclude Include="IZigWave.h">
<Filter>Interface Files</Filter>
</ClInclude>
<ClInclude Include="IMemoryMonitor.h" />
<Filter>Interface Files</Filter>
</ClInclude>
<ClInclude Include="ILocationSync.h">
<Filter>Interface Files</Filter>
</ClInclude>
Expand Down

0 comments on commit 0a4746d

Please sign in to comment.