Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.

Commit 6c52b04

Browse files
author
Jay Logue
committed
Make Java WirelessRegulatoryConfig class immutable
1 parent 676dab6 commit 6c52b04

File tree

3 files changed

+26
-20
lines changed

3 files changed

+26
-20
lines changed

src/device-manager/java/WeaveDeviceManager-JNI.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3519,7 +3519,7 @@ WEAVE_ERROR J2N_WirelessRegulatoryConfig(JNIEnv *env, jobject inRegConfig, Wirel
35193519
memcpy(outRegConfig.RegDomain.Code, strVal, sizeof(outRegConfig.RegDomain.Code));
35203520
}
35213521

3522-
err = J2N_EnumFieldVal(env, inRegConfig, "OpLocation", "Lnl/Weave/DeviceManager/OperatingLocation;", enumVal);
3522+
err = J2N_EnumFieldVal(env, inRegConfig, "OpLocation", "Lnl/Weave/DeviceManager/WirelessOperatingLocation;", enumVal);
35233523
SuccessOrExit(err);
35243524
outRegConfig.OpLocation = (uint8_t)enumVal;
35253525

@@ -3536,7 +3536,7 @@ WEAVE_ERROR J2N_WirelessRegulatoryConfig(JNIEnv *env, jobject inRegConfig, Wirel
35363536
WEAVE_ERROR N2J_WirelessRegulatoryConfig(JNIEnv *env, const WirelessRegConfig& inRegConfig, jobject& outRegConfig)
35373537
{
35383538
WEAVE_ERROR err = WEAVE_NO_ERROR;
3539-
jmethodID makeMethod;
3539+
jmethodID constructor;
35403540
jstring regDomain = NULL;
35413541
jobjectArray supportedRegDomains = NULL;
35423542
jclass java_lang_String = NULL;
@@ -3560,11 +3560,11 @@ WEAVE_ERROR N2J_WirelessRegulatoryConfig(JNIEnv *env, const WirelessRegConfig& i
35603560
});
35613561
SuccessOrExit(err);
35623562

3563-
makeMethod = env->GetStaticMethodID(sWirelessRegulatoryConfigCls, "Make", "(Ljava/lang/String;I[Ljava/lang/String;)Lnl/Weave/DeviceManager/WirelessRegulatoryConfig;");
3564-
VerifyOrExit(makeMethod != NULL, err = WDM_JNI_ERROR_METHOD_NOT_FOUND);
3563+
constructor = env->GetMethodID(sWirelessRegulatoryConfigCls, "<init>", "(Ljava/lang/String;I[Ljava/lang/String;)V");
3564+
VerifyOrExit(constructor != NULL, err = WDM_JNI_ERROR_METHOD_NOT_FOUND);
35653565

35663566
env->ExceptionClear();
3567-
outRegConfig = env->CallStaticObjectMethod(sWirelessRegulatoryConfigCls, makeMethod,
3567+
outRegConfig = (jthrowable)env->NewObject(sWirelessRegulatoryConfigCls, constructor,
35683568
regDomain, (jint)inRegConfig.OpLocation, supportedRegDomains);
35693569
VerifyOrExit(!env->ExceptionCheck(), err = WDM_JNI_ERROR_EXCEPTION_THROWN);
35703570

src/device-manager/java/src/nl/Weave/DeviceManager/TestMain.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ void RunUnitTests()
834834
TestResult = null;
835835
System.out.println("SetWirelessRegulatoryConfig Test");
836836
System.out.println(" Setting wireless regulatory configuration...");
837-
WirelessRegulatoryConfig regConfig = WirelessRegulatoryConfig.Make("CA", WirelessOperatingLocation.Indoors.val, null);
837+
WirelessRegulatoryConfig regConfig = new WirelessRegulatoryConfig("CA", WirelessOperatingLocation.Indoors);
838838
DeviceMgr.beginSetWirelessRegulatoryConfig(regConfig);
839839
ExpectSuccess("SetWirelessRegulatoryConfig");
840840
System.out.println("SetWirelessRegulatoryConfig Test Succeeded");

src/device-manager/java/src/nl/Weave/DeviceManager/WirelessRegulatoryConfig.java

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,39 @@
2121
/**
2222
* Container for wireless regulatory configuration information.
2323
*/
24-
public class WirelessRegulatoryConfig
24+
public final class WirelessRegulatoryConfig
2525
{
2626
/** Active wireless regulatory domain.
2727
*/
28-
public String RegDomain;
28+
public final String RegDomain;
2929

3030
/** Active operating location.
3131
*/
32-
public WirelessOperatingLocation OpLocation;
32+
public final WirelessOperatingLocation OpLocation;
3333

3434
/** Supported regulatory domains
3535
*/
36-
public String[] SupportedRegDomains;
36+
public final String[] SupportedRegDomains;
3737

38-
public WirelessRegulatoryConfig()
38+
public WirelessRegulatoryConfig(String regDomain, WirelessOperatingLocation opLocation)
3939
{
40-
RegDomain = null;
41-
OpLocation = WirelessOperatingLocation.NotSpecified;
42-
SupportedRegDomains = null;
40+
this.RegDomain = regDomain;
41+
this.OpLocation = opLocation;
42+
this.SupportedRegDomains = new String[0];
43+
}
44+
45+
public WirelessRegulatoryConfig(String regDomain, WirelessOperatingLocation opLocation, String[] supportedRegDomains)
46+
{
47+
this.RegDomain = regDomain;
48+
this.OpLocation = opLocation;
49+
this.SupportedRegDomains = supportedRegDomains.clone();
4350
}
4451

45-
public static WirelessRegulatoryConfig Make(String regDomain, int opLocation, String[] supportedRegDomains)
52+
// Convenience constructor for JNI code
53+
WirelessRegulatoryConfig(String regDomain, int opLocation, String[] supportedRegDomains)
4654
{
47-
WirelessRegulatoryConfig regConfig = new WirelessRegulatoryConfig();
48-
regConfig.RegDomain = regDomain;
49-
regConfig.OpLocation = WirelessOperatingLocation.fromVal(opLocation);
50-
regConfig.SupportedRegDomains = supportedRegDomains;
51-
return regConfig;
55+
this.RegDomain = regDomain;
56+
this.OpLocation = WirelessOperatingLocation.fromVal(opLocation);
57+
this.SupportedRegDomains = supportedRegDomains;
5258
}
5359
};

0 commit comments

Comments
 (0)