Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow piecemeal migration from EmberAf non-enum-class enums to cluster-objects enum classes #11900

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/app/zap-templates/templates/app/cluster-objects.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,22 @@ namespace Clusters {
{{#zcl_clusters}}
namespace {{asUpperCamelCase name}} {
{{#zcl_enums}}
{{#if (isWeaklyTypedEnum label)}}
// Need to convert consumers to using the new enum classes, so we
// don't just have casts all over.
#ifdef CHIP_USE_ENUM_CLASS_FOR_IM_ENUM
{{/if}}
// Enum for {{label}}
enum class {{asType label}} : {{asUnderlyingZclType type}} {
{{#zcl_enum_items}}
k{{asUpperCamelCase label}} = {{asHex value 2}},
{{/zcl_enum_items}}
};
{{#if (isWeaklyTypedEnum label)}}
#else // CHIP_USE_ENUM_CLASS_FOR_IM_ENUM
using {{asType label}} = EmberAf{{asType label}};
#endif
{{/if}}
{{/zcl_enums}}

{{#zcl_bitmaps}}
Expand Down
2 changes: 2 additions & 0 deletions src/app/zap-templates/templates/app/enums.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
{{#zcl_enums}}
{{#unless (isStrEqual label "Status")}}
{{#unless (isStrEqual label "ReportingDirection")}}
{{#if (isWeaklyTypedEnum label)}}

// Enum for {{label}}
enum EmberAf{{asType label}} : {{asUnderlyingZclType type}} {
{{#zcl_enum_items}}
{{ident}}EMBER_ZCL_{{asDelimitedMacro parent.label}}_{{asDelimitedMacro label}} = {{value}},
{{/zcl_enum_items}}
};
{{/if}}
{{/unless}}
{{/unless}}
{{/zcl_enums}}
Expand Down
82 changes: 82 additions & 0 deletions src/app/zap-templates/templates/app/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,87 @@ async function getResponseCommandName(responseRef, options)
return queryCommand.selectCommandById(db, responseRef, pkgId).then(response => asUpperCamelCase(response.name));
}

// Allow-list of enums that we generate as enums, not enum classes. The goal is
// to drive this down to 0.
function isWeaklyTypedEnum(label)
{
return [
"ApplicationBasicStatus",
"ApplicationLauncherStatus",
"AttributeWritePermission",
"AudioOutputType",
"BarrierControlBarrierPosition",
"BarrierControlMovingState",
"BootReasonType",
"ChangeReasonEnum",
"ColorControlOptions",
"ColorLoopAction",
"ColorLoopDirection",
"ColorMode",
"ContentLaunchStatus",
"ContentLaunchStreamingType",
"DoorLockEventSource",
"DoorLockEventType",
"DoorLockOperatingMode",
"DoorLockOperationEventCode",
"DoorLockProgrammingEventCode",
"DoorLockState",
"DoorLockUserStatus",
"DoorLockUserType",
"DoorState",
"EnhancedColorMode",
"HardwareFaultType",
"HueDirection",
"HueMoveMode",
"HueStepMode",
"IasEnrollResponseCode",
"IasZoneState",
"IasZoneType",
"IdentifyEffectIdentifier",
"IdentifyEffectVariant",
"IdentifyIdentifyType",
"InterfaceType",
"KeypadInputCecKeyCode",
"KeypadInputStatus",
"KeypadLockout",
"LevelControlOptions",
"MediaInputType",
"MediaPlaybackState",
"MediaPlaybackStatus",
"MoveMode",
"NetworkCommissioningError",
"NetworkFaultType",
"NodeOperationalCertStatus",
"OTAAnnouncementReason",
"OTAApplyUpdateAction",
"OTADownloadProtocol",
"OTAQueryStatus",
"OnOffDelayedAllOffEffectVariant",
"OnOffDyingLightEffectVariant",
"OnOffEffectIdentifier",
"PHYRateType",
"RadioFaultType",
"RoutingRole",
"RegulatoryLocationType",
"SaturationMoveMode",
"SaturationStepMode",
"SecurityType",
"SetpointAdjustMode",
"SimpleEnum",
"StartUpOnOffValue",
"StatusCode",
"StepMode",
"TemperatureDisplayMode",
"ThermostatControlSequence",
"ThermostatRunningMode",
"ThermostatSystemMode",
"UpdateStateEnum",
"WcEndProductType",
"WcType",
"WiFiVersionType",
].includes(label);
}

//
// Module exports
//
Expand All @@ -527,3 +608,4 @@ exports.zapTypeToEncodableClusterObjectType = zapTypeToEncodableClusterObjectTyp
exports.zapTypeToDecodableClusterObjectType = zapTypeToDecodableClusterObjectType;
exports.zapTypeToPythonClusterObjectType = zapTypeToPythonClusterObjectType;
exports.getResponseCommandName = getResponseCommandName;
exports.isWeaklyTypedEnum = isWeaklyTypedEnum;
8 changes: 4 additions & 4 deletions src/controller/java/templates/CHIPReadCallbacks-src.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ void CHIP{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}AttributeCallb
{{/if}}

{{#if isOptional}}
{{chipType}} {{asLowerCamelCase name}}Value;
{{zapTypeToDecodableClusterObjectType type forceNotOptional=true forceNotNullable=true ns=parent.parent.name}} {{asLowerCamelCase name}}Value;
{{#if isNullable}}
{{asLowerCamelCase name}}HasValue = entry.{{asLowerCamelCase name}}.HasValue();
if ({{asLowerCamelCase name}}HasValue) {
Expand All @@ -201,7 +201,7 @@ void CHIP{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}AttributeCallb

{{#unless isOptional}}
{{#unless isNullable}}
{{chipType}} {{asLowerCamelCase name}}Value = entry.{{asLowerCamelCase name}};
{{zapTypeToDecodableClusterObjectType type ns=parent.parent.name}} {{asLowerCamelCase name}}Value = entry.{{asLowerCamelCase name}};
{{/unless}}
{{/unless}}

Expand Down Expand Up @@ -265,13 +265,13 @@ void CHIP{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}AttributeCallb
bool entryNull = false;
{{#unless isStruct}}
{{#if isNullable}}
{{chipType}} entryValue;
{{zapTypeToDecodableClusterObjectType type ns=parent.name forceNotList=true}} entryValue;
entryNull = entry.IsNull();
if (!entryNull) {
entryValue = entry.Value();
}
{{else}}
{{chipType}} entryValue = entry;
{{zapTypeToDecodableClusterObjectType type ns=parent.name forceNotList=true}} entryValue = entry;
{{/if}}
{{/unless}}

Expand Down
2 changes: 1 addition & 1 deletion src/controller/java/templates/partials/decode_value.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if ({{source}}.Value().IsNull()) {
{{else}}
std::string {{target}}ClassName = "java/lang/{{asJavaBasicTypeForZclType type true}}";
std::string {{target}}CtorSignature = "({{asJniSignature type false}})V";
chip::JniReferences::GetInstance().CreateBoxedObject<{{chipType}}>({{target}}ClassName.c_str(), {{target}}CtorSignature.c_str(), {{>item}}, {{target}});
chip::JniReferences::GetInstance().CreateBoxedObject<{{zapTypeToDecodableClusterObjectType type ns=parent.parent.name forceNotNullable=true forceNotOptional=true}}>({{target}}ClassName.c_str(), {{target}}CtorSignature.c_str(), {{>item}}, {{target}});
{{/if}}
{{#if isOptional}}
chip::JniReferences::GetInstance().CreateOptional({{target}}, {{target}});
Expand Down
Loading