From 6d8a143adc28c7b9c1434b117f21c147667e4f26 Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Thu, 31 Jan 2013 17:45:21 +0100 Subject: Allow finer control of notification messages --- src/de/blinkt/openvpn/OpenVPN.java | 53 ++++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 13 deletions(-) (limited to 'src/de/blinkt/openvpn/OpenVPN.java') diff --git a/src/de/blinkt/openvpn/OpenVPN.java b/src/de/blinkt/openvpn/OpenVPN.java index 8d6cb4c8..9cfaf1e8 100644 --- a/src/de/blinkt/openvpn/OpenVPN.java +++ b/src/de/blinkt/openvpn/OpenVPN.java @@ -15,18 +15,23 @@ public class OpenVPN { private static Vector logListener; private static Vector stateListener; + private static Vector byteCountListener; + private static String[] mBconfig; - private static String mLaststatemsg; + private static String mLaststatemsg=""; - private static String mLaststate; + private static String mLaststate = "NOPROCESS"; private static int mLastStateresid=R.string.state_noprocess; + + private static long mlastByteCount[]={0,0,0,0}; static { logbuffer = new LinkedList(); logListener = new Vector(); stateListener = new Vector(); + byteCountListener = new Vector(); logInformation(); } @@ -83,7 +88,7 @@ public class OpenVPN { String str = String.format(Locale.ENGLISH,"Log (no context) resid %d", mRessourceId); if(mArgs !=null) for(Object o:mArgs) - str += "|" + o.toString(); + str += "|" + o.toString(); return str; } } @@ -107,6 +112,10 @@ public class OpenVPN { public interface StateListener { void updateState(String state, String logmessage, int localizedResId); } + + public interface ByteCountListener { + void updateByteCount(long in, long out, long diffin, long diffout); + } synchronized static void logMessage(int level,String prefix, String message) { @@ -131,14 +140,25 @@ public class OpenVPN { public synchronized static void removeLogListener(LogListener ll) { logListener.remove(ll); } + + public static void addByteCountListener(ByteCountListener bcl) { + bcl.updateByteCount(mlastByteCount[0], mlastByteCount[1], mlastByteCount[2], mlastByteCount[3]); + byteCountListener.add(bcl); + } + + public static void removeByteCountListener(ByteCountListener bcl) { + byteCountListener.remove(bcl); + } public synchronized static void addStateListener(StateListener sl){ - stateListener.add(sl); - if(mLaststate!=null) - sl.updateState(mLaststate, mLaststatemsg, mLastStateresid); + if(!stateListener.contains(sl)){ + stateListener.add(sl); + if(mLaststate!=null) + sl.updateState(mLaststate, mLaststatemsg, mLastStateresid); + } } - + private static int getLocalizedState(String state){ if (state.equals("CONNECTING")) return R.string.state_connecting; @@ -199,12 +219,10 @@ public class OpenVPN { } public synchronized static void updateStateString(String state, String msg, int resid) { - if (! "BYTECOUNT".equals(state)) { - mLaststate= state; - mLaststatemsg = msg; - mLastStateresid = resid; - } - + mLaststate= state; + mLaststatemsg = msg; + mLastStateresid = resid; + for (StateListener sl : stateListener) { sl.updateState(state,msg,resid); } @@ -240,4 +258,13 @@ public class OpenVPN { newlogItem(new LogItem(LogItem.ERROR, ressourceId,args)); } + public static void updateByteCount(long in, long out, long diffin, long diffout) { + mlastByteCount = new long[] {in,out,diffin,diffout}; + for(ByteCountListener bcl:byteCountListener){ + bcl.updateByteCount(in, out, diffin,diffout); + } + } + + + } -- cgit v1.2.3