@@ -1831,11 +1831,12 @@ static BOOL AttributeHasChangesOmittedQuality(MTRAttributePath * attributePath)
1831
1831
attributeID : (NSNumber *)attributeID
1832
1832
params : (MTRReadParams * _Nullable)params
1833
1833
{
1834
- #define ErrorStr " MTRDevice readAttributeWithEndpointID:clusterID:attributeID:params: must be handled by subclasses"
1835
- MTR_LOG_ERROR (ErrorStr );
1834
+ #define MTRDeviceErrorStr " MTRDevice readAttributeWithEndpointID:clusterID:attributeID:params: must be handled by subclasses"
1835
+ MTR_LOG_ERROR (MTRDeviceErrorStr );
1836
1836
#ifdef DEBUG
1837
- NSAssert (NO , @ErrorStr );
1837
+ NSAssert (NO , @MTRDeviceErrorStr );
1838
1838
#endif // DEBUG
1839
+ #undef MTRDeviceErrorStr
1839
1840
return nil ;
1840
1841
}
1841
1842
@@ -1846,120 +1847,12 @@ - (void)writeAttributeWithEndpointID:(NSNumber *)endpointID
1846
1847
expectedValueInterval : (NSNumber *)expectedValueInterval
1847
1848
timedWriteTimeout : (NSNumber * _Nullable)timeout
1848
1849
{
1849
- if (timeout) {
1850
- timeout = MTRClampedNumber (timeout, @(1 ), @(UINT16_MAX));
1851
- }
1852
- expectedValueInterval = MTRClampedNumber (expectedValueInterval, @(1 ), @(UINT32_MAX));
1853
- MTRAttributePath * attributePath = [MTRAttributePath attributePathWithEndpointID: endpointID
1854
- clusterID: clusterID
1855
-
1856
- attributeID: attributeID];
1857
-
1858
- __block BOOL useValueAsExpectedValue = YES ;
1850
+ #define MTRDeviceErrorStr " MTRDevice writeAttributeWithEndpointID:clusterID:attributeID:value:expectedValueInterval:timedWriteTimeout: must be handled by subclasses"
1851
+ MTR_LOG_ERROR (MTRDeviceErrorStr);
1859
1852
#ifdef DEBUG
1860
- os_unfair_lock_lock (&self->_lock );
1861
- [self _callFirstDelegateSynchronouslyWithBlock: ^(id delegate) {
1862
- if ([delegate respondsToSelector: @selector (unitTestShouldSkipExpectedValuesForWrite: )]) {
1863
- useValueAsExpectedValue = ![delegate unitTestShouldSkipExpectedValuesForWrite: self ];
1864
- }
1865
- }];
1866
- os_unfair_lock_unlock (&self->_lock );
1867
- #endif
1868
-
1869
- uint64_t expectedValueID = 0 ;
1870
- if (useValueAsExpectedValue) {
1871
- // Commit change into expected value cache
1872
- NSDictionary * newExpectedValueDictionary = @{ MTRAttributePathKey : attributePath, MTRDataKey : value };
1873
- [self setExpectedValues: @[ newExpectedValueDictionary ]
1874
- expectedValueInterval: expectedValueInterval
1875
- expectedValueID: &expectedValueID];
1876
- }
1877
-
1878
- MTRAsyncWorkItem * workItem = [[MTRAsyncWorkItem alloc ] initWithQueue: self .queue];
1879
- uint64_t workItemID = workItem.uniqueID ; // capture only the ID, not the work item
1880
- NSNumber * nodeID = _nodeID;
1881
-
1882
- // Write request data is an array of items (for now always length 1). Each
1883
- // item is an array containing:
1884
- //
1885
- // [ attribute path, value, timedWriteTimeout, expectedValueID ]
1886
- //
1887
- // where expectedValueID is stored as NSNumber and NSNull represents nil timeouts
1888
- auto * writeData = @[ attributePath, [value copy ], timeout ?: [NSNull null ], @(expectedValueID) ];
1889
-
1890
- NSMutableArray <NSArray *> * writeRequests = [NSMutableArray arrayWithObject: writeData];
1891
-
1892
- [workItem setBatchingID: MTRDeviceWorkItemBatchingWriteID data: writeRequests handler: ^(id opaqueDataCurrent, id opaqueDataNext) {
1893
- mtr_hide (self); // don't capture self accidentally
1894
- NSMutableArray <NSArray *> * writeRequestsCurrent = opaqueDataCurrent;
1895
- NSMutableArray <NSArray *> * writeRequestsNext = opaqueDataNext;
1896
-
1897
- if (writeRequestsCurrent.count != 1 ) {
1898
- // Very unexpected!
1899
- MTR_LOG_ERROR (" Batching write attribute work item [%llu]: Unexpected write request count %lu" , workItemID, static_cast <unsigned long >(writeRequestsCurrent.count ));
1900
- return MTRNotBatched;
1901
- }
1902
-
1903
- MTRBatchingOutcome outcome = MTRNotBatched;
1904
- while (writeRequestsNext.count ) {
1905
- // If paths don't match, we cannot replace the earlier write
1906
- // with the later one.
1907
- if (![writeRequestsNext[0 ][MTRDeviceWriteRequestFieldPathIndex]
1908
- isEqual: writeRequestsCurrent[0 ][MTRDeviceWriteRequestFieldPathIndex]]) {
1909
- MTR_LOG (" Batching write attribute work item [%llu]: cannot replace with next work item due to path mismatch" , workItemID);
1910
- return outcome;
1911
- }
1912
-
1913
- // Replace our one request with the first one from the next item.
1914
- auto writeItem = writeRequestsNext.firstObject ;
1915
- [writeRequestsNext removeObjectAtIndex: 0 ];
1916
- [writeRequestsCurrent replaceObjectAtIndex: 0 withObject: writeItem];
1917
- MTR_LOG (" Batching write attribute work item [%llu]: replaced with new write value %@ [0x%016llX]" ,
1918
- workItemID, writeItem, nodeID.unsignedLongLongValue );
1919
- outcome = MTRBatchedPartially;
1920
- }
1921
- NSCAssert (writeRequestsNext.count == 0 , @" should have batched everything or returned early" );
1922
- return MTRBatchedFully;
1923
- }];
1924
- // The write operation will install a duplicate check handler, to return NO for "isDuplicate". Since a write operation may
1925
- // change values, only read requests after this should be considered for duplicate requests.
1926
- [workItem setDuplicateTypeID: MTRDeviceWorkItemDuplicateReadTypeID handler: ^(id opaqueItemData, BOOL * isDuplicate, BOOL * stop) {
1927
- *isDuplicate = NO ;
1928
- *stop = YES ;
1929
- }];
1930
- [workItem setReadyHandler: ^(MTRDevice * self , NSInteger retryCount, MTRAsyncWorkCompletionBlock completion) {
1931
- MTRBaseDevice * baseDevice = [self newBaseDevice ];
1932
- // Make sure to use writeRequests here, because that's what our batching
1933
- // handler will modify as needed.
1934
- NSCAssert (writeRequests.count == 1 , @" Incorrect number of write requests: %lu " , static_cast <unsigned long >(writeRequests.count));
1935
-
1936
- auto * request = writeRequests[0 ];
1937
- MTRAttributePath * path = request[MTRDeviceWriteRequestFieldPathIndex];
1938
-
1939
- id timedWriteTimeout = request[MTRDeviceWriteRequestFieldTimeoutIndex];
1940
- if (timedWriteTimeout == [NSNull null ]) {
1941
- timedWriteTimeout = nil ;
1942
- }
1943
-
1944
- [baseDevice
1945
- writeAttributeWithEndpointID: path.endpoint
1946
- clusterID: path.cluster
1947
- attributeID: path.attribute
1948
- value: request[MTRDeviceWriteRequestFieldValueIndex]
1949
- timedWriteTimeout: timedWriteTimeout
1950
- queue: self .queue
1951
- completion: ^(NSArray <NSDictionary <NSString *, id > *> * _Nullable values, NSError * _Nullable error) {
1952
- if (error) {
1953
- MTR_LOG_ERROR (" Write attribute work item [%llu] failed: %@" , workItemID, error);
1954
- if (useValueAsExpectedValue) {
1955
- NSNumber * expectedValueID = request[MTRDeviceWriteRequestFieldExpectedValueIDIndex];
1956
- [self removeExpectedValueForAttributePath: attributePath expectedValueID: expectedValueID.unsignedLongLongValue];
1957
- }
1958
- }
1959
- completion (MTRAsyncWorkComplete);
1960
- }];
1961
- }];
1962
- [_asyncWorkQueue enqueueWorkItem: workItem descriptionWithFormat: @" write %@ 0x%llx 0x%llx " , endpointID, clusterID.unsignedLongLongValue, attributeID.unsignedLongLongValue];
1853
+ NSAssert (NO , @MTRDeviceErrorStr);
1854
+ #endif // DEBUG
1855
+ #undef MTRDeviceErrorStr
1963
1856
}
1964
1857
1965
1858
- (void )invokeCommandWithEndpointID : (NSNumber *)endpointID
@@ -2796,11 +2689,6 @@ - (NSArray *)_getAttributesToReportWithNewExpectedValues:(NSArray<NSDictionary<N
2796
2689
return attributesToReport;
2797
2690
}
2798
2691
2799
- - (void )setExpectedValues : (NSArray <NSDictionary<NSString *, id> *> *)values expectedValueInterval : (NSNumber *)expectedValueInterval
2800
- {
2801
- [self setExpectedValues: values expectedValueInterval: expectedValueInterval expectedValueID: nil ];
2802
- }
2803
-
2804
2692
// expectedValueID is an out-argument that returns an identifier to be used when removing expected values
2805
2693
- (void )setExpectedValues : (NSArray <NSDictionary<NSString *, id> *> *)values
2806
2694
expectedValueInterval : (NSNumber *)expectedValueInterval
@@ -2833,12 +2721,6 @@ - (void)removeExpectedValuesForAttributePaths:(NSArray<MTRAttributePath *> *)att
2833
2721
}
2834
2722
}
2835
2723
2836
- - (void )removeExpectedValueForAttributePath : (MTRAttributePath *)attributePath expectedValueID : (uint64_t )expectedValueID
2837
- {
2838
- std::lock_guard lock (_lock);
2839
- [self _removeExpectedValueForAttributePath: attributePath expectedValueID: expectedValueID];
2840
- }
2841
-
2842
2724
- (void )_removeExpectedValueForAttributePath : (MTRAttributePath *)attributePath expectedValueID : (uint64_t )expectedValueID
2843
2725
{
2844
2726
os_unfair_lock_assert_owner (&self->_lock );
0 commit comments