Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Sending network share

  • Loading branch information...
commit 070742c38bd460b6d44625f9fc9c15f2bc391d47 1 parent 7a436e1
@jonaias authored
View
49 src/org/AndroidShareApp/core/NetworkSender.java
@@ -10,6 +10,7 @@
import java.util.Iterator;
import org.AndroidShareApp.gui.SharedWithMeListActivity;
+import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@@ -79,6 +80,51 @@ public void sendDatagram(DatagramPacket packet){
}
}
+
+ /* Sends share info for everybody which
+ * this devices has shares
+ * TODO: Send every shared once*/
+ public void sendShareInfoForEverbody(){
+ Iterator<SharedByMeItem> sharedByMeItemIterator = NetworkManager.getInstance().getSharedByMeItems().iterator();
+ /* For each shared item */
+ while (sharedByMeItemIterator.hasNext()) {
+ SharedByMeItem sharedByMeItem = sharedByMeItemIterator.next();
+ Iterator<SharedPerson> sharedPersonIterator = sharedByMeItem.getSharedPersonList().iterator();
+ /* For each person which the item is shared */
+ while (sharedPersonIterator.hasNext()){
+ SharedPerson sharedPerson = sharedPersonIterator.next();
+ /* If shared person has access to the path */
+ if(sharedPerson.hasAnyAcess()){
+ JSONObject tempJsonObject = new JSONObject();
+ JSONArray sharedListJSON = new JSONArray();
+ JSONObject sharedItemJSON = new JSONObject();
+ /* Create and send shared item */
+ try {
+ tempJsonObject.put("messageType", NetworkProtocol.MESSAGE_SHARING_DETAILS_SEND);
+ tempJsonObject.put("deviceID", NetworkManager.getInstance().getThisDeviceId());
+
+ sharedItemJSON.put("path", sharedByMeItem.getSharedPath());
+
+ sharedItemJSON.put("permissions", sharedPerson.getPermissionString());
+
+ sharedListJSON.put(sharedItemJSON);
+
+ tempJsonObject.accumulate("sharedList",sharedListJSON);
+
+ DatagramPacket tempPacket = new DatagramPacket(tempJsonObject.toString().getBytes(), tempJsonObject.toString().getBytes().length ,
+ sharedPerson.getIP(), mPort);
+ sendDatagram(tempPacket);
+ } catch (JSONException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ }
+ }
+
+ }
+
@Override
public void run() {
@@ -109,6 +155,9 @@ public void run() {
/* Broadcasts live announcement */
sendDatagram(mPacket);
+ /* Broadcasts share info */
+ sendShareInfoForEverbody();
+
/* Wait 5s
* TODO: improve broadcast interval*/
try {
View
17 src/org/AndroidShareApp/core/SharedPerson.java
@@ -33,4 +33,21 @@ public void setRead (boolean canRead) {
public void setWrite (boolean canWrite) {
mWrite = canWrite;
}
+
+ /* Return permission string */
+ public String getPermissionString() {
+ String temp = "";
+ if(mRead){
+ temp+="r";
+ }
+ if(mWrite){
+ temp+="w";
+ }
+ return temp;
+ }
+
+ /* Returns ( canRead() || carWrite() )*/
+ public boolean hasAnyAcess(){
+ return canRead() || canWrite();
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.