forked from sensiasoft/sensorhub
-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement TCPServerCommProvider #241
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
56 changes: 34 additions & 22 deletions
56
sensorhub-core/src/main/java/org/sensorhub/api/comm/ICommProvider.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 |
---|---|---|
@@ -1,41 +1,53 @@ | ||
/***************************** BEGIN LICENSE BLOCK *************************** | ||
|
||
The contents of this file are subject to the Mozilla Public License, v. 2.0. | ||
If a copy of the MPL was not distributed with this file, You can obtain one | ||
at http://mozilla.org/MPL/2.0/. | ||
|
||
Software distributed under the License is distributed on an "AS IS" basis, | ||
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | ||
for the specific language governing rights and limitations under the License. | ||
|
||
Copyright (C) 2012-2015 Sensia Software LLC. All Rights Reserved. | ||
|
||
******************************* END LICENSE BLOCK ***************************/ | ||
The contents of this file are subject to the Mozilla Public License, v. 2.0. | ||
If a copy of the MPL was not distributed with this file, You can obtain one | ||
at http://mozilla.org/MPL/2.0/. | ||
|
||
Software distributed under the License is distributed on an "AS IS" basis, | ||
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | ||
for the specific language governing rights and limitations under the License. | ||
|
||
Copyright (C) 2012-2023 Sensia Software LLC. and Botts Innovative Research, Inc. All Rights Reserved. | ||
******************************* END LICENSE BLOCK ***************************/ | ||
|
||
package org.sensorhub.api.comm; | ||
|
||
import org.sensorhub.api.module.IModule; | ||
import org.sensorhub.impl.comm.ConnectionEventArgs; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import org.sensorhub.api.module.IModule; | ||
|
||
import java.util.function.Consumer; | ||
|
||
/** | ||
* <p> | ||
* Interface for all communication providers giving access to an input stream | ||
* for reading incoming data and an output stream for sending outgoing data. | ||
* </p> | ||
* | ||
* @author Alex Robin | ||
* @param <ConfigType> Comm module config type | ||
* @author Alex Robin | ||
* @since Jun 19, 2015 | ||
*/ | ||
public interface ICommProvider<ConfigType extends CommProviderConfig<?>> extends IModule<ConfigType> | ||
{ | ||
|
||
public InputStream getInputStream() throws IOException; | ||
|
||
|
||
public OutputStream getOutputStream() throws IOException; | ||
|
||
public interface ICommProvider<ConfigType extends CommProviderConfig<?>> extends IModule<ConfigType> { | ||
|
||
InputStream getInputStream() throws IOException; | ||
|
||
|
||
OutputStream getOutputStream() throws IOException; | ||
|
||
/** | ||
* Adds a connection event handler to this comm provider. | ||
* The handler will be called when a connection is established. | ||
* <p> | ||
* For client comm providers, this will be called when the comm module starts. | ||
* Make sure to register the handler before starting the module or the event will be missed. | ||
* <p> | ||
* For server comm providers, this will be called every time a client connects. | ||
* | ||
* @param eventHandler The event handler to add | ||
*/ | ||
void onConnection(Consumer<ConnectionEventArgs> eventHandler); | ||
} |
50 changes: 50 additions & 0 deletions
50
sensorhub-core/src/main/java/org/sensorhub/impl/comm/ConnectionEventArgs.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,50 @@ | ||
/***************************** BEGIN LICENSE BLOCK *************************** | ||
The contents of this file are subject to the Mozilla Public License, v. 2.0. | ||
If a copy of the MPL was not distributed with this file, You can obtain one | ||
at http://mozilla.org/MPL/2.0/. | ||
|
||
Software distributed under the License is distributed on an "AS IS" basis, | ||
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | ||
for the specific language governing rights and limitations under the License. | ||
|
||
Copyright (C) 2023 Botts Innovative Research Inc. All Rights Reserved. | ||
******************************* END LICENSE BLOCK ***************************/ | ||
|
||
package org.sensorhub.impl.comm; | ||
|
||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
|
||
/** | ||
* Event arguments for a connection event | ||
* | ||
* @author Michael Elmore | ||
* @since September 2023 | ||
*/ | ||
public class ConnectionEventArgs { | ||
private final InputStream inputStream; | ||
private final OutputStream outputStream; | ||
|
||
/** | ||
* @param inputStream The input stream for the connection | ||
* @param outputStream The output stream for the connection | ||
*/ | ||
public ConnectionEventArgs(InputStream inputStream, OutputStream outputStream) { | ||
this.inputStream = inputStream; | ||
this.outputStream = outputStream; | ||
} | ||
|
||
/** | ||
* @return The input stream for the connection | ||
*/ | ||
public InputStream getInputStream() { | ||
return inputStream; | ||
} | ||
|
||
/** | ||
* @return The output stream for the connection | ||
*/ | ||
public OutputStream getOutputStream() { | ||
return outputStream; | ||
} | ||
} |
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
46 changes: 46 additions & 0 deletions
46
sensorhub-core/src/main/java/org/sensorhub/impl/comm/TCPServerCommModuleDescriptor.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,46 @@ | ||
/***************************** BEGIN LICENSE BLOCK *************************** | ||
The contents of this file are subject to the Mozilla Public License, v. 2.0. | ||
If a copy of the MPL was not distributed with this file, You can obtain one | ||
at http://mozilla.org/MPL/2.0/. | ||
|
||
Software distributed under the License is distributed on an "AS IS" basis, | ||
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | ||
for the specific language governing rights and limitations under the License. | ||
|
||
Copyright (C) 2023 Botts Innovative Research Inc. All Rights Reserved. | ||
******************************* END LICENSE BLOCK ***************************/ | ||
|
||
package org.sensorhub.impl.comm; | ||
|
||
import org.sensorhub.api.module.IModule; | ||
import org.sensorhub.api.module.IModuleProvider; | ||
import org.sensorhub.api.module.ModuleConfig; | ||
import org.sensorhub.impl.module.JarModuleProvider; | ||
|
||
/** | ||
* Communication provider for TCP/IP server connections. | ||
* | ||
* @author Michael Elmore | ||
* @since September 2023 | ||
*/ | ||
public class TCPServerCommModuleDescriptor extends JarModuleProvider implements IModuleProvider { | ||
@Override | ||
public String getModuleName() { | ||
return "TCP Server Comm Driver"; | ||
} | ||
|
||
@Override | ||
public String getModuleDescription() { | ||
return "Simple TCP/IP server communication provider using JDK TCP stack"; | ||
} | ||
|
||
@Override | ||
public Class<? extends IModule<?>> getModuleClass() { | ||
return TCPServerCommProvider.class; | ||
} | ||
|
||
@Override | ||
public Class<? extends ModuleConfig> getModuleConfigClass() { | ||
return TCPServerCommProviderConfig.class; | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 Questions: