Project

General

Profile

« Previous | Next » 

Revision 63dd19c4

Added by Leszek Koltunski over 2 years ago

Progress downloading updates.

View differences:

src/main/java/org/distorted/network/RubikNetwork.java
52 52
    void error(String error);
53 53
    }
54 54

  
55
  public interface Updatee
56
    {
57
    void receiveUpdate(RubikUpdates update);
58
    void errorUpdate();
59
    }
60

  
55 61
  public static final int MAX_PLACES = 10;
56 62

  
57 63
  private static final int DOWNLOAD   = 0;
......
65 71
  private static final int REND_POWER = 2;
66 72
  private static final int REND_OTHER = 3;
67 73

  
74
  private static final int DEBUG_NOT_YET = 0;
75
  private static final int DEBUG_RUNNING = 1;
76
  private static final int DEBUG_SUCCESS = 2;
77
  private static final int DEBUG_FAILURE = 3;
78

  
68 79
  private final String[] hex = {
69 80
    "%00", "%01", "%02", "%03", "%04", "%05", "%06", "%07",
70 81
    "%08", "%09", "%0a", "%0b", "%0c", "%0d", "%0e", "%0f",
......
110 121
  private static boolean mRunning = false;
111 122
  private static int mMode = IDLE;
112 123
  private static Receiver mReceiver;
124
  private static Updatee mUpdatee;
113 125
  private static String mVersion;
114
  private static String mDebug;
126
  private static String mSuspicious;
115 127
  private static int mNumObjects;
116 128
  private static RubikUpdates mUpdates;
129
  private static int mDebugState;
117 130

  
118 131
///////////////////////////////////////////////////////////////////////////////////////////////////
119 132

  
......
396 409

  
397 410
      String updates = answer.toString();
398 411
      mUpdates.parse(updates);
412
      if( mUpdatee!=null ) mUpdatee.receiveUpdate(mUpdates);
413
      mDebugState = DEBUG_SUCCESS;
399 414
      }
400 415
    catch( final Exception e )
401 416
      {
402
      // ignore
417
      if( mUpdatee!=null ) mUpdatee.errorUpdate();
418
      mDebugState = DEBUG_FAILURE;
403 419
      }
404 420
    }
405 421

  
......
486 502
    {
487 503
    RubikScores scores = RubikScores.getInstance();
488 504
    int deviceID= scores.getDeviceID();
489
    String debug = URLencode(mDebug);
505
    String suspicious = URLencode(mSuspicious);
490 506

  
491 507
    String url="https://distorted.org/magic/cgi-bin/suspicious.cgi";
492
    url += "?i="+deviceID+"&d="+debug;
508
    url += "?i="+deviceID+"&d="+suspicious;
493 509

  
494 510
    return url;
495 511
    }
......
699 715

  
700 716
  public void debug(AppCompatActivity act)
701 717
    {
718
    mDebugState = DEBUG_RUNNING;
702 719
    start(null, act, DEBUG);
703 720
    }
704 721

  
705 722
///////////////////////////////////////////////////////////////////////////////////////////////////
706 723

  
707
  public void suspicious(AppCompatActivity act, String debug)
724
  public void suspicious(AppCompatActivity act, String suspicious)
708 725
    {
709
    mDebug = debug;
726
    mSuspicious = suspicious;
710 727
    start(null, act, SUSPICIOUS);
711 728
    }
729

  
730
///////////////////////////////////////////////////////////////////////////////////////////////////
731
// Yes it can happen that the second Updatee registers before we sent an update to the first one
732
// and, as a result, the update never gets sent to the first one. This is not a problem (now, when
733
// there are only two updatees - the RubikStatePlay and the UpdateDialog)
734
//
735
// Yes, there is also a remote possibility that the two threads executing this function and executing
736
// the sendDebug() get swapped exactly in unlucky moment and the update never gets to the updatee.
737
// We don't care about such remote possibility, then the app simply would signal that there are no
738
// updates available.
739

  
740
  public void signUpForUpdates(Updatee updatee)
741
    {
742
         if( mDebugState==DEBUG_SUCCESS ) updatee.receiveUpdate(mUpdates);
743
    else if( mDebugState==DEBUG_FAILURE ) updatee.errorUpdate();
744
    else mUpdatee = updatee;
745
    }
712 746
}

Also available in: Unified diff