mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
Store settings in the DB, listen for events when settings are updated.
This commit is contained in:
6
briar-api/src/org/briarproject/api/Settings.java
Normal file
6
briar-api/src/org/briarproject/api/Settings.java
Normal file
@@ -0,0 +1,6 @@
|
||||
package org.briarproject.api;
|
||||
|
||||
public class Settings extends StringMap {
|
||||
|
||||
private static final long serialVersionUID = 8439364293077111359L;
|
||||
}
|
||||
29
briar-api/src/org/briarproject/api/StringMap.java
Normal file
29
briar-api/src/org/briarproject/api/StringMap.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package org.briarproject.api;
|
||||
|
||||
import java.util.Hashtable;
|
||||
import java.util.Map;
|
||||
|
||||
abstract class StringMap extends Hashtable<String, String> {
|
||||
|
||||
private static final long serialVersionUID = 2497176435908100448L;
|
||||
|
||||
protected StringMap(Map<String, String> m) {
|
||||
super(m);
|
||||
}
|
||||
|
||||
protected StringMap() {
|
||||
super();
|
||||
}
|
||||
|
||||
public boolean getBoolean(String key, boolean defaultValue) {
|
||||
String s = get(key);
|
||||
if(s == null) return defaultValue;
|
||||
if("true".equals(s)) return true;
|
||||
if("false".equals(s)) return false;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public void putBoolean(String key, boolean value) {
|
||||
put(key, String.valueOf(value));
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,16 @@
|
||||
package org.briarproject.api;
|
||||
|
||||
import java.util.Hashtable;
|
||||
import java.util.Map;
|
||||
|
||||
public class TransportConfig extends Hashtable<String, String> {
|
||||
public class TransportConfig extends StringMap {
|
||||
|
||||
private static final long serialVersionUID = 2330384620787778596L;
|
||||
|
||||
public TransportConfig(Map<String, String> c) {
|
||||
super(c);
|
||||
public TransportConfig(Map<String, String> m) {
|
||||
super(m);
|
||||
}
|
||||
|
||||
public TransportConfig() {}
|
||||
public TransportConfig() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
package org.briarproject.api;
|
||||
|
||||
import java.util.Hashtable;
|
||||
import java.util.Map;
|
||||
|
||||
public class TransportProperties extends Hashtable<String, String> {
|
||||
public class TransportProperties extends StringMap {
|
||||
|
||||
private static final long serialVersionUID = 7533739534204953625L;
|
||||
|
||||
public TransportProperties(Map<String, String> p) {
|
||||
super(p);
|
||||
public TransportProperties(Map<String, String> m) {
|
||||
super(m);
|
||||
}
|
||||
|
||||
public TransportProperties() {}
|
||||
public TransportProperties() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.briarproject.api.AuthorId;
|
||||
import org.briarproject.api.Contact;
|
||||
import org.briarproject.api.ContactId;
|
||||
import org.briarproject.api.LocalAuthor;
|
||||
import org.briarproject.api.Settings;
|
||||
import org.briarproject.api.TransportConfig;
|
||||
import org.briarproject.api.TransportId;
|
||||
import org.briarproject.api.TransportProperties;
|
||||
@@ -233,6 +234,9 @@ public interface DatabaseComponent {
|
||||
/** Returns all temporary secrets. */
|
||||
Collection<TemporarySecret> getSecrets() throws DbException;
|
||||
|
||||
/** Returns all settings. */
|
||||
Settings getSettings() throws DbException;
|
||||
|
||||
/** Returns the maximum latencies of all local transports. */
|
||||
Map<TransportId, Long> getTransportLatencies() throws DbException;
|
||||
|
||||
@@ -263,6 +267,9 @@ public interface DatabaseComponent {
|
||||
void mergeLocalProperties(TransportId t, TransportProperties p)
|
||||
throws DbException;
|
||||
|
||||
/** Merges the given settings with the existing settings. */
|
||||
void mergeSettings(Settings s) throws DbException;
|
||||
|
||||
/** Processes an ack from the given contact. */
|
||||
void receiveAck(ContactId c, Ack a) throws DbException;
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
package org.briarproject.api.event;
|
||||
|
||||
/** An event that is broadcast when one or more settings are updated. */
|
||||
public class SettingsUpdatedEvent extends Event {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user