]> rtime.felk.cvut.cz Git - orte/eurobot.git/blob - orte/java/src/org/ocera/orte/examples/hello/HelloMsg.java
JORTE: add deserialize function to support endianness setting
[orte/eurobot.git] / orte / java / src / org / ocera / orte / examples / hello / HelloMsg.java
1 /* HelloMsg.java */
2
3 /* ********************************************************* *
4  *                                                           *
5  *                Will be Generated by IDL                   *
6  *                                                           *
7  * ********************************************************* */
8
9 import org.ocera.orte.*;
10 import org.ocera.orte.types.*;
11
12 public class HelloMsg extends org.ocera.orte.types.MessageData
13 {
14    private int counter = 0;
15    public int count_read = 0; // pro testovaci ucely!!
16
17 /* ************************************** * 
18  *               data to send             *
19  * ************************************** */
20
21    public  int    num1;
22    public  int    num2;   
23    
24 /* ************************************** */
25
26    
27   /* constructor  */
28   public HelloMsg(DomainApp domainApp, String newTopic)
29   {
30     super();
31  
32     // typeName registration
33         if(counter == 0)
34     {
35              boolean b;
36                  
37              counter++;
38          this.setTopic(newTopic); // set the topic of a publication 
39          // register new data typeName     
40          b = domainApp.regNewDataType(this.getType(),getMaxDataLength(),this.buffer); 
41              if (b == false) 
42              {
43                System.out.println(":j!: cannot register data type!");    
44              }
45
46            }
47         // init
48             num1 = 0;
49         num2 = 0;  
50         //System.out.println(":j: instance of HelloMsg created..");     
51   }
52       
53
54   /**
55    * Serializetaion method. Put all of data fields and write them into a buffer. 
56    * @return True - if write successful, False - write failed (IndexOutOfBoundsException or ReadOnlyBufferException).  
57    */
58   /* TODO osetrit vyjimky - mozna pak bude vracet typ boolean 
59    * IndexOutOfBoundsException - If index is negative or not smaller than the buffer's limit 
60    * ReadOnlyBufferException - If this buffer is read-only
61    */ 
62   public void write()
63   {
64         /* TODO - control setting fields !!*/
65     num1 = 49;
66     num2 = 50;
67         //
68         buffer.rewind(); // set offset to 0
69         buffer.putInt(this.num1);
70         buffer.putInt(this.num2);       
71   }
72  
73   /**
74    * Serializetaion method. Put all of data fields and write them into a buffer. 
75    * @return True - if write successful, False - write failed (IndexOutOfBoundsException or ReadOnlyBufferException).  
76    */
77   /* TODO 'BufferUnderflowException' - osetrit vyjimky - mozna pak bude vracet typ boolean 
78
79    */ 
80   public void read()
81   {
82         buffer.rewind(); // set offset to 0
83         this.num1 = buffer.getInt();                    
84         this.num2 = buffer.getInt();
85   }
86
87   /**
88    * Return maximum buffer's length according to its data fields.
89    * @return Length of buffer.
90    **/  
91   public int getMaxDataLength()
92   {
93         int len=0;
94         len += ORTEConstant.INT_FIELD_SIZE;
95         len += ORTEConstant.INT_FIELD_SIZE;
96     return len;
97   }
98
99   public String toString()
100   {
101     String data = new String();
102     
103     data += (" num1 = " + num1); 
104     data += (" num2 = " + num2);        
105         return data;      
106   }
107   
108 }