-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move the invoke request to invoke element
rename the invoke request to invoke element since this class would be used in request and response.
- Loading branch information
1 parent
1023101
commit a152600
Showing
3 changed files
with
101 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
src/controller/java/src/chip/devicecontroller/model/InvokeElement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Copyright (c) 2023 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* 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. | ||
* | ||
*/ | ||
package chip.devicecontroller.model; | ||
|
||
import java.util.Locale; | ||
import java.util.Objects; | ||
|
||
/** An invoke request that should be used for interaction model invoke command. */ | ||
public final class InvokeRequest { | ||
private final ChipPathId endpointId, clusterId, commandId; | ||
private final byte[] tlv; | ||
|
||
private InvokeRequest( | ||
ChipPathId endpointId, ChipPathId clusterId, ChipPathId commandId, byte[] tlv) { | ||
this.endpointId = endpointId; | ||
this.clusterId = clusterId; | ||
this.commandId = commandId; | ||
this.tlv = tlv.clone(); | ||
} | ||
|
||
public ChipPathId getEndpointId() { | ||
return endpointId; | ||
} | ||
|
||
public ChipPathId getClusterId() { | ||
return clusterId; | ||
} | ||
|
||
public ChipPathId getCommandId() { | ||
return commandId; | ||
} | ||
|
||
public byte[] getTlvByteArray() { | ||
return tlv.clone(); | ||
} | ||
|
||
// check whether the current InvokeRequest has same path as others. | ||
@Override | ||
public boolean equals(Object object) { | ||
if (object instanceof InvokeRequest) { | ||
InvokeRequest that = (InvokeRequest) object; | ||
return Objects.equals(this.endpointId, that.endpointId) | ||
&& Objects.equals(this.clusterId, that.clusterId) | ||
&& Objects.equals(this.commandId, that.commandId); | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(endpointId, clusterId, commandId); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format( | ||
Locale.ENGLISH, "Endpoint %s, cluster %s, command %s", endpointId, clusterId, commandId); | ||
} | ||
|
||
public static InvokeRequest newInstance( | ||
ChipPathId endpointId, ChipPathId clusterId, ChipPathId commandId, byte[] tlv) { | ||
return new InvokeRequest(endpointId, clusterId, commandId, tlv); | ||
} | ||
|
||
/** Create a new {@link InvokeRequest} with only concrete ids. */ | ||
public static InvokeRequest newInstance( | ||
long endpointId, long clusterId, long commandId, byte[] tlv) { | ||
return new InvokeRequest( | ||
ChipPathId.forId(endpointId), | ||
ChipPathId.forId(clusterId), | ||
ChipPathId.forId(commandId), | ||
tlv); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters