-
Notifications
You must be signed in to change notification settings - Fork 408
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "transport" command to leshan-client-demo.
- Loading branch information
1 parent
a15a513
commit eb8badc
Showing
16 changed files
with
717 additions
and
78 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
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
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
25 changes: 25 additions & 0 deletions
25
...ain/java/org/eclipse/leshan/client/demo/cli/transport/DefaultEndpointProviderFactory.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,25 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Sierra Wireless and others. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* and Eclipse Distribution License v1.0 which accompany this distribution. | ||
* | ||
* The Eclipse Public License is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* and the Eclipse Distribution License is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.html. | ||
* | ||
* Contributors: | ||
* Sierra Wireless - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.leshan.client.demo.cli.transport; | ||
|
||
import org.eclipse.leshan.client.demo.cli.LeshanClientDemoCLI; | ||
import org.eclipse.leshan.client.endpoint.LwM2mClientEndpointsProvider; | ||
|
||
import picocli.CommandLine; | ||
|
||
public interface DefaultEndpointProviderFactory { | ||
LwM2mClientEndpointsProvider createDefault(LeshanClientDemoCLI cli, CommandLine commandLine); | ||
} |
26 changes: 26 additions & 0 deletions
26
...o/src/main/java/org/eclipse/leshan/client/demo/cli/transport/EndpointProviderFactory.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,26 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Sierra Wireless and others. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* and Eclipse Distribution License v1.0 which accompany this distribution. | ||
* | ||
* The Eclipse Public License is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* and the Eclipse Distribution License is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.html. | ||
* | ||
* Contributors: | ||
* Sierra Wireless - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.leshan.client.demo.cli.transport; | ||
|
||
import org.eclipse.leshan.client.demo.cli.LeshanClientDemoCLI; | ||
import org.eclipse.leshan.client.endpoint.LwM2mClientEndpointsProvider; | ||
|
||
import picocli.CommandLine.ParseResult; | ||
|
||
public interface EndpointProviderFactory { | ||
|
||
LwM2mClientEndpointsProvider create(LeshanClientDemoCLI cli, ParseResult result); | ||
} |
83 changes: 83 additions & 0 deletions
83
...ent-demo/src/main/java/org/eclipse/leshan/client/demo/cli/transport/TransportCommand.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,83 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Sierra Wireless and others. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* and Eclipse Distribution License v1.0 which accompany this distribution. | ||
* | ||
* The Eclipse Public License is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* and the Eclipse Distribution License is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.html. | ||
* | ||
* Contributors: | ||
* Sierra Wireless - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.leshan.client.demo.cli.transport; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.eclipse.leshan.client.demo.cli.LeshanClientDemoCLI; | ||
import org.eclipse.leshan.client.demo.cli.transport.californium.CaliforniumCommand; | ||
import org.eclipse.leshan.client.demo.cli.transport.javacoap.JavaCoapCommand; | ||
import org.eclipse.leshan.client.endpoint.LwM2mClientEndpointsProvider; | ||
import org.eclipse.leshan.core.demo.cli.PicocliUtil; | ||
|
||
import picocli.CommandLine; | ||
import picocli.CommandLine.Command; | ||
import picocli.CommandLine.Option; | ||
|
||
@Command(name = "transport", | ||
description = { | ||
"Configure Leshan transport layer. Can be used to add, remove or use different implementation of supported LWM2M transport.", // | ||
"%n"// | ||
+ CaliforniumCommand.DEFAULT_DESCRIPTION // | ||
+ CaliforniumCommand.DEFAULT_COMMAND_DESCRIPTION // | ||
+ "%n" // | ||
+ "@|italic More examples :|@%n" // | ||
+ CaliforniumCommand.COMMON_USAGE // | ||
+ "%n" // | ||
+ JavaCoapCommand.COMMON_USAGE // | ||
+ "%n" // | ||
+ "coaps support based on Californium library and coap support based java-coap library: %n" // | ||
+ "@|bold transport californium coaps java-coap coap|@%n"// | ||
+ "%n" // | ||
+ "Launch @|bold transport [californium|java-coap] -h|@ for more details.%n" // | ||
}, | ||
subcommandsRepeatable = true, | ||
subcommands = { CaliforniumCommand.class, JavaCoapCommand.class }) | ||
public class TransportCommand implements Runnable { | ||
|
||
@Option(names = { "-h", "--help" }, description = "Display help information.", usageHelp = true) | ||
private boolean help; | ||
|
||
@Override | ||
public void run() { | ||
} | ||
|
||
public List<LwM2mClientEndpointsProvider> createEndpointsProviders(LeshanClientDemoCLI cli, | ||
CommandLine commandLine) { | ||
|
||
// if transport sub-command is called | ||
if (commandLine.getParseResult() != null && commandLine.getParseResult().hasSubcommand()) { | ||
List<LwM2mClientEndpointsProvider> providers = new ArrayList<>(); | ||
|
||
// add provider from call sub-commands | ||
PicocliUtil.applyTo(commandLine.getParseResult(), EndpointProviderFactory.class, // | ||
(parseResult, endpointProviderFactory) -> { | ||
providers.add(endpointProviderFactory.create(cli, parseResult)); | ||
}); | ||
return providers; | ||
} | ||
// else create default providers | ||
else { | ||
List<LwM2mClientEndpointsProvider> providers = new ArrayList<>(); | ||
PicocliUtil.applyTo(commandLine, DefaultEndpointProviderFactory.class, // | ||
(cmd, endpointProviderFactory) -> { | ||
providers.add(endpointProviderFactory.createDefault(cli, cmd)); | ||
}); | ||
return providers; | ||
} | ||
} | ||
} |
Oops, something went wrong.