Skip to content

Commit

Permalink
zap-initial
Browse files Browse the repository at this point in the history
  • Loading branch information
pgregorr-amazon committed Feb 28, 2024
1 parent 116317f commit 5c8f7f1
Show file tree
Hide file tree
Showing 43 changed files with 14,727 additions and 180 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
objects = {

/* Begin PBXBuildFile section */
39BF57C52B8CFF790081653C /* MCAttributeObjects.h in Headers */ = {isa = PBXBuildFile; fileRef = 39BF57C42B8CFF790081653C /* MCAttributeObjects.h */; };
39BF57C72B8CFFB90081653C /* MCAttributeObjects.mm in Sources */ = {isa = PBXBuildFile; fileRef = 39BF57C62B8CFFB90081653C /* MCAttributeObjects.mm */; };
39BF57C92B8D66540081653C /* NSStringSpanConversion.h in Headers */ = {isa = PBXBuildFile; fileRef = 39BF57C82B8D66540081653C /* NSStringSpanConversion.h */; };
39BF57CB2B8E54F80081653C /* NSDataSpanConversion.h in Headers */ = {isa = PBXBuildFile; fileRef = 39BF57CA2B8E54F80081653C /* NSDataSpanConversion.h */; };
3C0474062B3F7E5F0012AE95 /* MCEndpointFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 3C0474052B3F7E5F0012AE95 /* MCEndpointFilter.h */; };
3C04740C2B4604CF0012AE95 /* MCCryptoUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 3C04740B2B4604CF0012AE95 /* MCCryptoUtils.h */; };
3C04740E2B4605B40012AE95 /* MCCryptoUtils.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3C04740D2B4605B40012AE95 /* MCCryptoUtils.mm */; };
Expand Down Expand Up @@ -42,8 +46,6 @@
3C621CA72B605AA1005CDBA3 /* MCObserver.h in Headers */ = {isa = PBXBuildFile; fileRef = 3C621CA62B605AA1005CDBA3 /* MCObserver.h */; };
3C621CA92B605C52005CDBA3 /* MCAttribute_Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = 3C621CA82B605C52005CDBA3 /* MCAttribute_Internal.h */; };
3C621CAB2B605C6E005CDBA3 /* MCAttribute.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3C621CAA2B605C6E005CDBA3 /* MCAttribute.mm */; };
3C621CAD2B605E94005CDBA3 /* MCAttributeObjects.h in Headers */ = {isa = PBXBuildFile; fileRef = 3C621CAC2B605E94005CDBA3 /* MCAttributeObjects.h */; };
3C621CAF2B605EA7005CDBA3 /* MCAttributeObjects.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3C621CAE2B605EA7005CDBA3 /* MCAttributeObjects.mm */; };
3C66FBFC290327BB00B63FE7 /* AppParameters.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3C66FBFB290327BB00B63FE7 /* AppParameters.mm */; };
3C6920462AA1093300D0F613 /* MCDeviceAttestationCredentialsProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 3C6920452AA1093300D0F613 /* MCDeviceAttestationCredentialsProvider.h */; };
3C6920482AA1094000D0F613 /* MCDeviceAttestationCredentialsProvider.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3C6920472AA1094000D0F613 /* MCDeviceAttestationCredentialsProvider.mm */; };
Expand Down Expand Up @@ -80,6 +82,10 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
39BF57C42B8CFF790081653C /* MCAttributeObjects.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MCAttributeObjects.h; sourceTree = "<group>"; };
39BF57C62B8CFFB90081653C /* MCAttributeObjects.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = MCAttributeObjects.mm; sourceTree = "<group>"; };
39BF57C82B8D66540081653C /* NSStringSpanConversion.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NSStringSpanConversion.h; sourceTree = "<group>"; };
39BF57CA2B8E54F80081653C /* NSDataSpanConversion.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NSDataSpanConversion.h; sourceTree = "<group>"; };
3C0474052B3F7E5F0012AE95 /* MCEndpointFilter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MCEndpointFilter.h; sourceTree = "<group>"; };
3C04740B2B4604CF0012AE95 /* MCCryptoUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MCCryptoUtils.h; sourceTree = "<group>"; };
3C04740D2B4605B40012AE95 /* MCCryptoUtils.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = MCCryptoUtils.mm; sourceTree = "<group>"; };
Expand Down Expand Up @@ -120,8 +126,6 @@
3C621CA62B605AA1005CDBA3 /* MCObserver.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MCObserver.h; sourceTree = "<group>"; };
3C621CA82B605C52005CDBA3 /* MCAttribute_Internal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MCAttribute_Internal.h; sourceTree = "<group>"; };
3C621CAA2B605C6E005CDBA3 /* MCAttribute.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = MCAttribute.mm; sourceTree = "<group>"; };
3C621CAC2B605E94005CDBA3 /* MCAttributeObjects.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MCAttributeObjects.h; sourceTree = "<group>"; usesTabs = 0; };
3C621CAE2B605EA7005CDBA3 /* MCAttributeObjects.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = MCAttributeObjects.mm; sourceTree = "<group>"; };
3C66FBFA2903279A00B63FE7 /* AppParameters.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppParameters.h; sourceTree = "<group>"; };
3C66FBFB290327BB00B63FE7 /* AppParameters.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = AppParameters.mm; sourceTree = "<group>"; };
3C6920452AA1093300D0F613 /* MCDeviceAttestationCredentialsProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MCDeviceAttestationCredentialsProvider.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -177,6 +181,15 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
395241F42B854EA700F7DB91 /* zap-generated */ = {
isa = PBXGroup;
children = (
39BF57C42B8CFF790081653C /* MCAttributeObjects.h */,
39BF57C62B8CFFB90081653C /* MCAttributeObjects.mm */,
);
path = "zap-generated";
sourceTree = "<group>";
};
3C94378A2B3654720096E5F4 /* Core */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -219,6 +232,7 @@
3CCB871F2869085400771BAD /* MatterTvCastingBridge */ = {
isa = PBXGroup;
children = (
395241F42B854EA700F7DB91 /* zap-generated */,
3C94378A2B3654720096E5F4 /* Core */,
3C94378B2B36547A0096E5F4 /* Support */,
3C94378C2B3654960096E5F4 /* Clusters */,
Expand Down Expand Up @@ -247,8 +261,6 @@
3C4F52352B5733A200BB8A10 /* MCClusterObjects.mm */,
3C621CA02B5F6CF8005CDBA3 /* MCCommandObjects.h */,
3C621CA22B5F6D08005CDBA3 /* MCCommandObjects.mm */,
3C621CAC2B605E94005CDBA3 /* MCAttributeObjects.h */,
3C621CAE2B605EA7005CDBA3 /* MCAttributeObjects.mm */,
3C4F521F2B507C4A00BB8A10 /* MCEndpointClusterType.h */,
3C4F52132B4F31DC00BB8A10 /* MCDeviceTypeStruct.h */,
3C4F52152B4F31FA00BB8A10 /* MCDeviceTypeStruct.m */,
Expand All @@ -272,6 +284,8 @@
3C9437932B3B47A10096E5F4 /* MCErrorUtils.mm */,
3C04740B2B4604CF0012AE95 /* MCCryptoUtils.h */,
3C04740D2B4605B40012AE95 /* MCCryptoUtils.mm */,
39BF57CA2B8E54F80081653C /* NSDataSpanConversion.h */,
39BF57C82B8D66540081653C /* NSStringSpanConversion.h */,
3CCB873A286A593700771BAD /* CastingServerBridge.h */,
3CCB873D286A593700771BAD /* CastingServerBridge.mm */,
3C66FBFA2903279A00B63FE7 /* AppParameters.h */,
Expand Down Expand Up @@ -322,12 +336,14 @@
3C621CA52B605A6A005CDBA3 /* MCAttribute.h in Headers */,
3CD73F1C2A9E8396009D82D1 /* MCCommissionableDataProvider.h in Headers */,
3C4F521E2B4F4B3B00BB8A10 /* MCEndpoint_Internal.h in Headers */,
39BF57C92B8D66540081653C /* NSStringSpanConversion.h in Headers */,
3C4F52262B50899700BB8A10 /* MCCluster_Internal.h in Headers */,
3CF71C0A2A992D0D003A5CE5 /* MCCastingApp.h in Headers */,
3C4F521C2B4F4B1B00BB8A10 /* MCCastingPlayer_Internal.h in Headers */,
3CD73F172A9E6884009D82D1 /* MCRotatingDeviceIdUniqueIdProvider.h in Headers */,
3C4F52102B4E18C800BB8A10 /* MCEndpoint.h in Headers */,
3C4F52282B51DB3000BB8A10 /* MCCommand.h in Headers */,
39BF57CB2B8E54F80081653C /* NSDataSpanConversion.h in Headers */,
3C621CA92B605C52005CDBA3 /* MCAttribute_Internal.h in Headers */,
3CF71C102A99312D003A5CE5 /* MCCommissionableData.h in Headers */,
3C4F522A2B51DFAE00BB8A10 /* MCCommand_Internal.h in Headers */,
Expand All @@ -345,7 +361,7 @@
3C621CA12B5F6CF8005CDBA3 /* MCCommandObjects.h in Headers */,
3C4F52202B507C4A00BB8A10 /* MCEndpointClusterType.h in Headers */,
3C6920462AA1093300D0F613 /* MCDeviceAttestationCredentialsProvider.h in Headers */,
3C621CAD2B605E94005CDBA3 /* MCAttributeObjects.h in Headers */,
39BF57C52B8CFF790081653C /* MCAttributeObjects.h in Headers */,
3C04740C2B4604CF0012AE95 /* MCCryptoUtils.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -465,7 +481,7 @@
3C4F52362B5733A200BB8A10 /* MCClusterObjects.mm in Sources */,
3CD73F1E2A9E83C1009D82D1 /* MCCommissionableDataProvider.mm in Sources */,
3CD73F222A9EA078009D82D1 /* MCDeviceAttestationCredentials.mm in Sources */,
3C621CAF2B605EA7005CDBA3 /* MCAttributeObjects.mm in Sources */,
39BF57C72B8CFFB90081653C /* MCAttributeObjects.mm in Sources */,
3C2346252B362BBB00FA276E /* MCCastingPlayerDiscovery.mm in Sources */,
3C4F52242B507CA800BB8A10 /* MCCluster.mm in Sources */,
3C66FBFC290327BB00B63FE7 /* AppParameters.mm in Sources */,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@

- (instancetype _Nonnull)initWithCppAttribute:(void * _Nonnull)cppAttribute;

- (id _Nullable)getObjTypeFromCpp:(std::any)cppValue;
- (id _Nullable)getObjCTypeFromCpp:(std::any)cppValue errorCode:(CHIP_ERROR * _Nonnull)aError;

@end

template <typename TypeInfo>
class MCAttributeTemplate {
public:
MCAttributeTemplate(void * _Nonnull cppAttribute,
std::function<id(std::any)> getObjTypeFromCppFn)
std::function<id(std::any, CHIP_ERROR * _Nonnull)> getObjCTypeFromCppFn)
{
mCppAttribute = cppAttribute;
mGetObjTypeFromCppFn = getObjTypeFromCppFn;
mGetObjCTypeFromCppFn = getObjCTypeFromCppFn;
}

void read(void * _Nullable context, std::function<void(void * _Nullable, id _Nullable, id _Nullable, NSError * _Nullable)> completion)
Expand All @@ -58,18 +58,23 @@ class MCAttributeTemplate {

attribute->Read(
context,
[clientQueue, completion, this](void * context, chip::Optional<typename TypeInfo::DecodableArgType> before, typename TypeInfo::DecodableArgType after) {
[clientQueue, completion, this](void * context, chip::Optional<typename TypeInfo::DecodableType> before, typename TypeInfo::DecodableArgType after) {
NSNumber *objCBefore = nil, *objCAfter = nil;
CHIP_ERROR errBefore = CHIP_NO_ERROR, errAfter = CHIP_NO_ERROR;
if (before.HasValue()) {
ChipLogProgress(AppServer, "<MCAttributeTemplate> converting 'before' value from Cpp to ObjC");
std::any anyBefore = std::any(std::make_shared<typename TypeInfo::DecodableArgType>(before.Value()));
objCBefore = mGetObjTypeFromCppFn(anyBefore);
std::any anyBefore = std::any(std::make_shared<typename TypeInfo::DecodableType>(before.Value()));
objCBefore = mGetObjCTypeFromCppFn(anyBefore, &errBefore);
}
ChipLogProgress(AppServer, "<MCAttributeTemplate> converting 'after' value from Cpp to ObjC");
std::any anyAfter = std::any(std::make_shared<typename TypeInfo::DecodableArgType>(after));
objCAfter = mGetObjTypeFromCppFn(anyAfter);
std::any anyAfter = std::any(std::make_shared<typename TypeInfo::DecodableType>(after));
objCAfter = mGetObjCTypeFromCppFn(anyAfter, &errAfter);
dispatch_async(clientQueue, ^{
completion(context, objCBefore, objCAfter, nil);
if (errBefore == CHIP_NO_ERROR && errAfter == CHIP_NO_ERROR) {
completion(context, objCBefore, objCAfter, nil);
} else {
completion(context, nil, nil, [MCErrorUtils NSErrorFromChipError:(errAfter != CHIP_NO_ERROR ? errAfter : errBefore)]);
}
});
},
[clientQueue, completion](void * context, CHIP_ERROR error) {
Expand All @@ -89,18 +94,23 @@ class MCAttributeTemplate {

attribute->Subscribe(
context,
[clientQueue, completion, this](void * context, chip::Optional<typename TypeInfo::DecodableArgType> before, typename TypeInfo::DecodableArgType after) {
[clientQueue, completion, this](void * context, chip::Optional<typename TypeInfo::DecodableType> before, typename TypeInfo::DecodableArgType after) {
NSNumber *objCBefore = nil, *objCAfter = nil;
CHIP_ERROR errBefore = CHIP_NO_ERROR, errAfter = CHIP_NO_ERROR;
if (before.HasValue()) {
ChipLogProgress(AppServer, "<MCAttributeTemplate> converting 'before' value from Cpp to ObjC");
std::any anyBefore = std::any(std::make_shared<typename TypeInfo::DecodableArgType>(before.Value()));
objCBefore = mGetObjTypeFromCppFn(anyBefore);
std::any anyBefore = std::any(std::make_shared<typename TypeInfo::DecodableType>(before.Value()));
objCBefore = mGetObjCTypeFromCppFn(anyBefore, &errBefore);
}
ChipLogProgress(AppServer, "<MCAttributeTemplate> converting 'after' value from Cpp to ObjC");
std::any anyAfter = std::any(std::make_shared<typename TypeInfo::DecodableArgType>(after));
objCAfter = mGetObjTypeFromCppFn(anyAfter);
std::any anyAfter = std::any(std::make_shared<typename TypeInfo::DecodableType>(after));
objCAfter = mGetObjCTypeFromCppFn(anyAfter, &errAfter);
dispatch_async(clientQueue, ^{
completion(context, objCBefore, objCAfter, nil);
if (errBefore == CHIP_NO_ERROR && errAfter == CHIP_NO_ERROR) {
completion(context, objCBefore, objCAfter, nil);
} else {
completion(context, nil, nil, [MCErrorUtils NSErrorFromChipError:(errAfter != CHIP_NO_ERROR ? errAfter : errBefore)]);
}
});
},
[clientQueue, completion](void * context, CHIP_ERROR error) {
Expand All @@ -115,6 +125,6 @@ class MCAttributeTemplate {

private:
void * _Nonnull mCppAttribute;
std::function<id(std::any)> mGetObjTypeFromCppFn;
std::function<id(std::any, CHIP_ERROR * _Nonnull)> mGetObjCTypeFromCppFn;
};
#endif /* MCAttribute_Internal_h */
Loading

0 comments on commit 5c8f7f1

Please sign in to comment.