1 | /************************************************************************************ |
---|
2 | * Copyright (C) 2008 by Politehnica University of Bucharest and Rutgers University |
---|
3 | * All rights reserved. |
---|
4 | * Refer to LICENSE for terms and conditions of use. |
---|
5 | ***********************************************************************************/ |
---|
6 | package vnsim.applications.vitp.utils; |
---|
7 | |
---|
8 | |
---|
9 | import java.util.*; |
---|
10 | |
---|
11 | import vnsim.map.object.Cross; |
---|
12 | import vnsim.map.object.Globals; |
---|
13 | import vnsim.map.object.Point; |
---|
14 | import vnsim.map.object.Road; |
---|
15 | |
---|
16 | |
---|
17 | |
---|
18 | public class VITPReply extends VITPMessage { |
---|
19 | |
---|
20 | /** <code>serialVersionUID</code> */ |
---|
21 | private static final long serialVersionUID = -5883719321862303634L; |
---|
22 | |
---|
23 | private String status; //can be "OK", "ERROR" |
---|
24 | |
---|
25 | private int ttl; //used in the caching mechanism |
---|
26 | |
---|
27 | public VITPReply( short roadIdx1Dst, short fromDst, short toDst, |
---|
28 | short roadIdx1Src, short fromSrc, short toSrc, |
---|
29 | Date initialTime, Date expirationTime, String cacheControl, |
---|
30 | int msgId, String msgBody, int ttl, String status) { |
---|
31 | |
---|
32 | super(roadIdx1Dst, fromDst, toDst, |
---|
33 | roadIdx1Src, fromSrc, toSrc, |
---|
34 | initialTime, expirationTime, cacheControl, msgId, msgBody); |
---|
35 | this.ttl=ttl; |
---|
36 | this.status=status; |
---|
37 | this.type=VITP_REP; |
---|
38 | } |
---|
39 | |
---|
40 | public String toString(){ |
---|
41 | String ret=super.toString(); |
---|
42 | ret=ret+";STATUS="+status+"--"; |
---|
43 | return ret; |
---|
44 | } |
---|
45 | |
---|
46 | public void setStatus(String status){ |
---|
47 | this.status=status; |
---|
48 | } |
---|
49 | |
---|
50 | public String getUserFriendlyText() { |
---|
51 | String ret=""; |
---|
52 | ret+="Status:"+status+"\n"; |
---|
53 | ret+="Message came from:\n"; |
---|
54 | Road r=(Road)Globals.map.roads.get(this.source.roadIndex); |
---|
55 | ret+="Road : "+r.getName(); |
---|
56 | Point ptmid=(Point)r.points.get((this.source.pt1+this.source.pt2)/2); |
---|
57 | Point pt1=(Point)r.points.get(this.source.pt1); |
---|
58 | Point pt2=(Point)r.points.get(this.source.pt2); |
---|
59 | // ret+="\nSegment length: "+Math.abs(pt1.getDistance()-pt2.getDistance()); |
---|
60 | for(int i=0;i<r.crosses.size();i++) { |
---|
61 | Cross c=(Cross)r.crosses.get(i); |
---|
62 | if(c.getPointIndex()==0) { |
---|
63 | ret+=" \nFrom "+((int)(pt1.getDistance()*1000))+"meters away from "+(((Road)(Globals.map.roads.get(c.getCrossRoadIndex()))).getName()); |
---|
64 | } |
---|
65 | } |
---|
66 | ret+="\n Message content:\n"+this.msgBody; |
---|
67 | ret+="\n***"; |
---|
68 | return ret; |
---|
69 | } |
---|
70 | } |
---|