|
@@ -45,6 +45,8 @@ import de.tudarmstadt.informatik.hostage.R;
|
|
|
import de.tudarmstadt.informatik.hostage.logging.Record;
|
|
|
import de.tudarmstadt.informatik.hostage.logging.SyncData;
|
|
|
import de.tudarmstadt.informatik.hostage.logging.SyncInfo;
|
|
|
+import de.tudarmstadt.informatik.hostage.persistence.HostageDBOpenHelper;
|
|
|
+import de.tudarmstadt.informatik.hostage.sync.Synchronizer;
|
|
|
import de.tudarmstadt.informatik.hostage.ui.activity.MainActivity;
|
|
|
|
|
|
public class P2PSyncActivity extends Activity implements WifiP2pManager.GroupInfoListener, WifiP2pManager.PeerListListener, WifiP2pManager.ChannelListener, AdapterView.OnItemClickListener, WifiP2pManager.ConnectionInfoListener {
|
|
@@ -75,6 +77,9 @@ public class P2PSyncActivity extends Activity implements WifiP2pManager.GroupInf
|
|
|
private ClientAsyncTask clientAsync;
|
|
|
private ServerAsyncTask serverAsync;
|
|
|
|
|
|
+ private HostageDBOpenHelper mDbHelper;
|
|
|
+ private Synchronizer synchronizer;
|
|
|
+
|
|
|
private void extractFromView(){
|
|
|
mTxtP2PDeviceName = (TextView) findViewById(R.id.txt_p2p_device_name);
|
|
|
mTxtP2PDeviceStatus = (TextView) findViewById(R.id.txt_p2p_device_status);
|
|
@@ -155,6 +160,9 @@ public class P2PSyncActivity extends Activity implements WifiP2pManager.GroupInf
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
|
+ mDbHelper = new HostageDBOpenHelper(getApplicationContext());
|
|
|
+ synchronizer = new Synchronizer(mDbHelper);
|
|
|
+
|
|
|
setContentView(R.layout.activity_p2_psync);
|
|
|
|
|
|
assert getActionBar() != null;
|
|
@@ -278,14 +286,14 @@ public class P2PSyncActivity extends Activity implements WifiP2pManager.GroupInf
|
|
|
if(connectedPeer != null && mInfo != null){
|
|
|
Log.i("peers", mInfo.groupFormed + " - " + mInfo.isGroupOwner);
|
|
|
Log.i("server", "Starting async server!");
|
|
|
- serverAsync = new ServerAsyncTask(this, OWNER_SERVER_PORT);
|
|
|
+ serverAsync = new ServerAsyncTask(this, OWNER_SERVER_PORT, synchronizer);
|
|
|
serverAsync.execute();
|
|
|
}
|
|
|
//new ClientAsyncTask(this, mOtherDevice.deviceAddress, CLIENT_SERVER_PORT).execute();
|
|
|
} else if(info.groupFormed){
|
|
|
//new ServerAsyncTask(this, CLIENT_SERVER_PORT).execute();
|
|
|
Log.i("client", "Starting async client!");
|
|
|
- clientAsync = new ClientAsyncTask(this, mInfo.groupOwnerAddress.getHostAddress(), OWNER_SERVER_PORT);
|
|
|
+ clientAsync = new ClientAsyncTask(this, mInfo.groupOwnerAddress.getHostAddress(), OWNER_SERVER_PORT, synchronizer);
|
|
|
clientAsync.execute();
|
|
|
}
|
|
|
}
|
|
@@ -340,14 +348,16 @@ public class P2PSyncActivity extends Activity implements WifiP2pManager.GroupInf
|
|
|
private Activity context;
|
|
|
private int port;
|
|
|
private final ProgressDialog progressDialog;
|
|
|
+ private final Synchronizer synchronizer;
|
|
|
|
|
|
/**
|
|
|
* @param context
|
|
|
*/
|
|
|
- public ServerAsyncTask(Activity context, int port) {
|
|
|
+ public ServerAsyncTask(Activity context, int port, Synchronizer synchronizer) {
|
|
|
this.context = context;
|
|
|
this.port = port;
|
|
|
this.progressDialog = new ProgressDialog(context);
|
|
|
+ this.synchronizer = synchronizer;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -394,7 +404,6 @@ public class P2PSyncActivity extends Activity implements WifiP2pManager.GroupInf
|
|
|
thisSyncInfo.deviceMap.put("dev1", 12L);
|
|
|
thisSyncInfo.deviceMap.put("dev2", 13L);
|
|
|
|
|
|
-
|
|
|
oos.writeObject(thisSyncInfo);
|
|
|
oos.flush();
|
|
|
publishProgress(3);
|
|
@@ -411,7 +420,7 @@ public class P2PSyncActivity extends Activity implements WifiP2pManager.GroupInf
|
|
|
|
|
|
// --- 3. send sync data
|
|
|
SyncData mySyncData = new SyncData();
|
|
|
- mySyncData.records.add(new Record());
|
|
|
+ //mySyncData.records.add(new Record());
|
|
|
|
|
|
oos.writeObject(mySyncData);
|
|
|
oos.flush();
|
|
@@ -449,6 +458,7 @@ public class P2PSyncActivity extends Activity implements WifiP2pManager.GroupInf
|
|
|
private static final int SOCKET_TIMEOUT = 10000;
|
|
|
private int tryNum = 0;
|
|
|
private final ProgressDialog progressDialog;
|
|
|
+ private final Synchronizer synchronizer;
|
|
|
|
|
|
@Override
|
|
|
protected void onPreExecute() {
|
|
@@ -465,11 +475,12 @@ public class P2PSyncActivity extends Activity implements WifiP2pManager.GroupInf
|
|
|
/**
|
|
|
* @param context
|
|
|
*/
|
|
|
- public ClientAsyncTask(Context context, String host, int port) {
|
|
|
+ public ClientAsyncTask(Context context, String host, int port, Synchronizer synchronizer) {
|
|
|
this.context = context;
|
|
|
this.host = host;
|
|
|
this.port = port;
|
|
|
this.progressDialog = new ProgressDialog(context);
|
|
|
+ this.synchronizer = synchronizer;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -495,6 +506,7 @@ public class P2PSyncActivity extends Activity implements WifiP2pManager.GroupInf
|
|
|
|
|
|
oos.writeObject(thisSyncInfo);
|
|
|
oos.flush();
|
|
|
+
|
|
|
publishProgress(2);
|
|
|
|
|
|
// --- 1. Receive sync info
|
|
@@ -510,7 +522,7 @@ public class P2PSyncActivity extends Activity implements WifiP2pManager.GroupInf
|
|
|
|
|
|
// --- 2. Send sync data
|
|
|
SyncData thisSyncData = new SyncData();
|
|
|
- thisSyncData.records.add(new Record());
|
|
|
+ //thisSyncData.records.add(new Record());
|
|
|
oos.writeObject(thisSyncData);
|
|
|
oos.flush();
|
|
|
publishProgress(4);
|