Skip to content

Commit 05d268d

Browse files
committed
Initial implementation
Signed-off-by: Riccardo Binetti <[email protected]>
1 parent 9b03c33 commit 05d268d

File tree

85 files changed

+4966
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+4966
-0
lines changed

.gitignore

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Built application files
2+
*.apk
3+
*.ap_
4+
*.aab
5+
6+
# Files for the ART/Dalvik VM
7+
*.dex
8+
9+
# Java class files
10+
*.class
11+
12+
# Generated files
13+
bin/
14+
gen/
15+
out/
16+
release/
17+
18+
# Gradle files
19+
.gradle/
20+
build/
21+
22+
# Local configuration file (sdk path, etc)
23+
local.properties
24+
25+
# Proguard folder generated by Eclipse
26+
proguard/
27+
28+
# Log Files
29+
*.log
30+
31+
# Android Studio Navigation editor temp files
32+
.navigation/
33+
34+
# Android Studio captures folder
35+
captures/
36+
37+
# IntelliJ
38+
*.iml
39+
.idea/workspace.xml
40+
.idea/tasks.xml
41+
.idea/gradle.xml
42+
.idea/assetWizardSettings.xml
43+
.idea/dictionaries
44+
.idea/libraries
45+
# Android Studio 3 in .gitignore file.
46+
.idea/caches
47+
.idea/modules.xml
48+
# Comment next line if keeping position of elements in Navigation Editor is relevant for you
49+
.idea/navEditor.xml
50+
51+
# Keystore files
52+
# Uncomment the following lines if you do not want to check your keystore files in.
53+
#*.jks
54+
#*.keystore
55+
56+
# External native build folder generated in Android Studio 2.2 and later
57+
.externalNativeBuild
58+
59+
# Google Services (e.g. APIs or Firebase)
60+
# google-services.json
61+
62+
# Freeline
63+
freeline.py
64+
freeline/
65+
freeline_project_description.json
66+
67+
# fastlane
68+
fastlane/report.xml
69+
fastlane/Preview.html
70+
fastlane/screenshots
71+
fastlane/test_output
72+
fastlane/readme.md
73+
74+
# Version control
75+
vcs.xml
76+
77+
# lint
78+
lint/intermediates/
79+
lint/generated/
80+
lint/outputs/
81+
lint/tmp/
82+
# lint/reports/
83+
84+
# other
85+
.idea
86+
87+
# LS
88+
.project
89+
.settings/
90+
.classpath

DeviceSDK/build.gradle

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
plugins {
2+
id 'java-library'
3+
}
4+
5+
repositories {
6+
maven {
7+
url "https://repo.eclipse.org/content/repositories/paho-releases/"
8+
}
9+
}
10+
11+
dependencies {
12+
implementation fileTree(dir: 'libs', include: ['*.jar'])
13+
14+
api 'org.json:json:20200518'
15+
16+
implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.5'
17+
18+
implementation 'org.mongodb:bson:3.11.0'
19+
20+
api 'org.bouncycastle:bcpkix-jdk15on:1.62'
21+
22+
implementation 'commons-io:commons-io:2.6'
23+
implementation 'javax.xml.bind:jaxb-api:2.3.1'
24+
implementation 'xerces:xercesImpl:2.12.0'
25+
26+
implementation 'com.squareup.okhttp3:okhttp:4.1.0'
27+
28+
api 'joda-time:joda-time:2.9.7'
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package org.astarteplatform.devicesdk;
2+
3+
import java.util.Collection;
4+
import java.util.HashMap;
5+
import java.util.Map;
6+
import org.astarteplatform.devicesdk.crypto.AstarteCryptoException;
7+
import org.astarteplatform.devicesdk.protocol.AstarteGlobalEventListener;
8+
import org.astarteplatform.devicesdk.protocol.AstarteInterface;
9+
import org.astarteplatform.devicesdk.protocol.AstarteInvalidInterfaceException;
10+
import org.astarteplatform.devicesdk.protocol.AstarteServerAggregateDatastreamInterface;
11+
import org.astarteplatform.devicesdk.protocol.AstarteServerDatastreamInterface;
12+
import org.astarteplatform.devicesdk.protocol.AstarteServerPropertyInterface;
13+
import org.astarteplatform.devicesdk.transport.AstarteFailedMessageStorage;
14+
import org.astarteplatform.devicesdk.transport.AstarteTransportException;
15+
import org.json.JSONException;
16+
import org.json.JSONObject;
17+
18+
public abstract class AstarteDevice {
19+
private final Map<String, AstarteInterface> mAstarteInterfaces;
20+
protected final AstartePropertyStorage mPropertyStorage;
21+
protected final AstarteFailedMessageStorage mFailedMessageStorage;
22+
protected boolean mAlwaysReconnect = false;
23+
24+
AstarteDevice(
25+
AstarteInterfaceProvider astarteInterfaceProvider,
26+
AstartePropertyStorage propertyStorage,
27+
AstarteFailedMessageStorage failedMessageStorage)
28+
throws JSONException, AstarteInvalidInterfaceException {
29+
mPropertyStorage = propertyStorage;
30+
mFailedMessageStorage = failedMessageStorage;
31+
Collection<JSONObject> astarteInterfaces = astarteInterfaceProvider.loadAllInterfaces();
32+
mAstarteInterfaces = new HashMap<>();
33+
for (JSONObject astarteInterface : astarteInterfaces) {
34+
AstarteInterface theInterface = AstarteInterface.fromJSON(astarteInterface, mPropertyStorage);
35+
mAstarteInterfaces.put(theInterface.getInterfaceName(), theInterface);
36+
}
37+
}
38+
39+
public boolean hasInterface(String interfaceName) {
40+
return mAstarteInterfaces.containsKey(interfaceName);
41+
}
42+
43+
public Collection<String> getAllInterfaceNames() {
44+
return mAstarteInterfaces.keySet();
45+
}
46+
47+
public Collection<AstarteInterface> getAllInterfaces() {
48+
return mAstarteInterfaces.values();
49+
}
50+
51+
public AstarteInterface getInterface(String interfaceName) {
52+
return mAstarteInterfaces.get(interfaceName);
53+
}
54+
55+
public void addGlobalEventListener(AstarteGlobalEventListener eventListener) {
56+
for (Map.Entry<String, AstarteInterface> interfaceEntry : mAstarteInterfaces.entrySet()) {
57+
AstarteInterface astarteInterface = interfaceEntry.getValue();
58+
if (astarteInterface instanceof AstarteServerPropertyInterface) {
59+
((AstarteServerPropertyInterface) astarteInterface).addListener(eventListener);
60+
} else if (astarteInterface instanceof AstarteServerDatastreamInterface) {
61+
((AstarteServerDatastreamInterface) astarteInterface).addListener(eventListener);
62+
} else if (astarteInterface instanceof AstarteServerAggregateDatastreamInterface) {
63+
((AstarteServerAggregateDatastreamInterface) astarteInterface).addListener(eventListener);
64+
}
65+
}
66+
}
67+
68+
public void removeGlobalListener(AstarteGlobalEventListener eventListener) {
69+
for (Map.Entry<String, AstarteInterface> interfaceEntry : mAstarteInterfaces.entrySet()) {
70+
AstarteInterface astarteInterface = interfaceEntry.getValue();
71+
if (astarteInterface instanceof AstarteServerPropertyInterface) {
72+
((AstarteServerPropertyInterface) astarteInterface).removeListener(eventListener);
73+
} else if (astarteInterface instanceof AstarteServerDatastreamInterface) {
74+
((AstarteServerDatastreamInterface) astarteInterface).removeListener(eventListener);
75+
} else if (astarteInterface instanceof AstarteServerAggregateDatastreamInterface) {
76+
((AstarteServerAggregateDatastreamInterface) astarteInterface)
77+
.removeListener(eventListener);
78+
}
79+
}
80+
}
81+
82+
public abstract String getDeviceId();
83+
84+
public abstract String getAstarteRealm();
85+
86+
public abstract AstarteMessageListener getAstarteMessageListener();
87+
88+
public abstract void setAstarteMessageListener(AstarteMessageListener astarteMessageListener);
89+
90+
public abstract void connect()
91+
throws AstarteTransportException, AstarteCryptoException, AstartePairingException;
92+
93+
public abstract void disconnect() throws AstarteTransportException;
94+
95+
public abstract boolean isConnected();
96+
97+
public boolean alwaysReconnects() {
98+
return mAlwaysReconnect;
99+
}
100+
101+
public void setAlwaysReconnect(boolean alwaysReconnect) {
102+
this.mAlwaysReconnect = alwaysReconnect;
103+
}
104+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.astarteplatform.devicesdk;
2+
3+
import java.util.Collection;
4+
import org.json.JSONObject;
5+
6+
public interface AstarteInterfaceProvider {
7+
Collection<JSONObject> loadAllInterfaces();
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.astarteplatform.devicesdk;
2+
3+
public interface AstarteMessageListener {
4+
void onConnected();
5+
6+
void onDisconnected(Throwable cause);
7+
8+
void onFailure(Throwable cause);
9+
}

0 commit comments

Comments
 (0)