OpenECHO
 All Classes Namespaces Files Functions Variables
ProfileObject.java
Go to the documentation of this file.
1 /*
2  * Copyright 2012 Sony Computer Science Laboratories, Inc. <info@kadecot.net>
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.sonycsl.echo.eoj.profile;
17 
18 import java.util.HashSet;
19 import java.util.Iterator;
20 
27 import com.sonycsl.echo.eoj.EchoObject.Getter;
28 import com.sonycsl.echo.eoj.EchoObject.Informer;
29 import com.sonycsl.echo.eoj.device.DeviceObject.Setter;
31 
32 public abstract class ProfileObject extends EchoObject {
33 
34  public static final byte EPC_FAULT_STATUS = (byte)0x88;
35  public static final byte EPC_MANUFACTURER_CODE = (byte)0x8A;
36  public static final byte EPC_PLACE_OF_BUSINESS_CODE = (byte)0x8B;
37  public static final byte EPC_PRODUCT_CODE = (byte)0x8C;
38  public static final byte EPC_SERIAL_NUMBER = (byte)0x8D;
39  public static final byte EPC_DATE_OF_MANUFACTURE = (byte)0x8E;
40  public static final byte EPC_STATUS_CHANGE_ANNOUNCEMENT_PROPERTY_MAP = (byte)0x9D;
41  public static final byte EPC_SET_PROPERTY_MAP = (byte)0x9E;
42  public static final byte EPC_GET_PROPERTY_MAP = (byte)0x9F;
43 
44  @Override
45  protected void setupPropertyMaps() {
46  super.setupPropertyMaps();
47 
52  }
53 
54  @Override
55  public void onNew() {
56  super.onNew();
57  Echo.getEventListener().onNewProfileObject(this);
58  }
59 
60 
61  @Override
62  protected synchronized boolean setProperty(EchoProperty property) {
63  boolean success = super.setProperty(property);
64  if(success) return success;
65 
66  switch(property.epc) {
67  default : return false;
68  }
69  }
70 
71  @Override
72  protected synchronized byte[] getProperty(byte epc) {
73  byte[] edt = super.getProperty(epc);
74  if(edt != null) return edt;
75 
76  switch(epc) {
77  case EPC_FAULT_STATUS : return getFaultStatus();
80  case EPC_PRODUCT_CODE : return getProductCode();
81  case EPC_SERIAL_NUMBER : return getSerialNumber();
86  default : return null;
87  }
88  }
89 
90  @Override
91  protected synchronized boolean isValidProperty(EchoProperty property) {
92  boolean valid = super.isValidProperty(property);
93  if(valid) return valid;
94 
95  switch(property.epc) {
96  case EPC_FAULT_STATUS : return isValidFaultStatus(property.edt);
97  case EPC_MANUFACTURER_CODE : return isValidManufacturerCode(property.edt);
99  case EPC_PRODUCT_CODE : return isValidProductCode(property.edt);
100  case EPC_SERIAL_NUMBER : return isValidSerialNumber(property.edt);
101  case EPC_DATE_OF_MANUFACTURE : return isValidDateOfManufacture(property.edt);
103  case EPC_SET_PROPERTY_MAP : return isValidSetPropertyMap(property.edt);
104  case EPC_GET_PROPERTY_MAP : return isValidGetPropertyMap(property.edt);
105  default : return false;
106  }
107  }
108 /*
109  @Override
110  protected boolean onReceiveProperty(EchoProperty property) {
111  boolean ret = super.onReceiveProperty(property);
112  if(ret) return ret;
113 
114  switch(property.epc) {
115  case EPC_STATUS_CHANGE_ANNOUNCEMENT_PROPERTY_MAP :
116  onReceiveStatusChangeAnnouncementPropertyMap(property.edt);
117  return true;
118  case EPC_SET_PROPERTY_MAP :
119  onReceiveSetPropertyMap(property.edt);
120  return true;
121  case EPC_GET_PROPERTY_MAP :
122  onReceiveGetPropertyMap(property.edt);
123  return true;
124  default :
125  return false;
126  }
127  }*/
128 
129  private void onReceiveStatusChangeAnnouncementPropertyMap(byte[] edt) {
130  byte[] properties = EchoUtils.propertyMapToProperties(edt);
131  if(properties == null || properties.length == 0) return;
133  for(byte p : properties) {
135  }
136  }
137 
138  private void onReceiveSetPropertyMap(byte[] edt) {
139  byte[] properties = EchoUtils.propertyMapToProperties(edt);
140  if(properties == null || properties.length == 0) return;
142  for(byte p : properties) {
143  addSetProperty(p);
144  }
145  }
146 
147  private void onReceiveGetPropertyMap(byte[] edt) {
148  byte[] properties = EchoUtils.propertyMapToProperties(edt);
149  if(properties == null || properties.length == 0) return;
151  for(byte p : properties) {
152  addGetProperty(p);
153  }
154  }
155 
156 
165  protected byte[] getFaultStatus() {
166  return null;
167  }
168 
169  protected boolean isValidFaultStatus(byte[] edt) {
170  if(edt == null || !(edt.length == 1)) return false;
171  return true;
172  }
181  protected abstract byte[] getManufacturerCode();
182 
183  protected boolean isValidManufacturerCode(byte[] edt) {
184  if(edt == null || !(edt.length == 3)) return false;
185  return true;
186  }
187 
196  protected byte[] getPlaceOfBusinessCode() {
197  return null;
198  }
199 
200  protected boolean isValidPlaceOfBusinessCode(byte[] edt) {
201  if(edt == null || !(edt.length == 3)) return false;
202  return true;
203  }
204 
213  protected byte[] getProductCode() {
214  return null;
215  }
216 
217  protected boolean isValidProductCode(byte[] edt) {
218  if(edt == null || !(edt.length == 12)) return false;
219  return true;
220  }
221 
230  protected byte[] getSerialNumber() {
231  return null;
232  }
233 
234  protected boolean isValidSerialNumber(byte[] edt) {
235  if(edt == null || !(edt.length == 12)) return false;
236  return true;
237  }
238 
249  protected byte[] getDateOfManufacture() {
250  return null;
251  }
252 
253  protected boolean isValidDateOfManufacture(byte[] edt) {
254  if(edt == null || !(edt.length == 4)) return false;
255  return true;
256  }
257 
266  return EchoUtils.propertiesToPropertyMap(getStatusChangeAnnouncementProperties());
267  }
268 
269  protected boolean isValidStatusChangeAnnouncementPropertyMap(byte[] edt) {
270  if(edt == null || !(edt.length <= 17)) return false;
271  return true;
272  }
273 
281  protected byte[] getSetPropertyMap() {
282  return EchoUtils.propertiesToPropertyMap(getSetProperties());
283  }
284  protected boolean isValidSetPropertyMap(byte[] edt) {
285  if(edt == null || !(edt.length <= 17)) return false;
286  return true;
287  }
288 
296  protected byte[] getGetPropertyMap() {
297  return EchoUtils.propertiesToPropertyMap(getGetProperties());
298  }
299  protected boolean isValidGetPropertyMap(byte[] edt) {
300  if(edt == null || !(edt.length <= 17)) return false;
301  return true;
302  }
303 
304 
305  @Override
306  public Setter set() {
307  return set(true);
308  }
309 
310  @Override
311  public Setter set(boolean responseRequired) {
312  return new Setter(getEchoClassCode(), getInstanceCode()
313  , getNode().getAddressStr(), responseRequired);
314  }
315 
316  @Override
317  public Getter get() {
318  return new Getter(getEchoClassCode(), getInstanceCode()
319  , getNode().getAddressStr());
320  }
321 
322  @Override
323  public Informer inform() {
324  return inform(isSelfObject());
325  }
326 
327  @Override
328  protected Informer inform(boolean multicast) {
329  String address;
330  if(multicast) {
332  } else {
333  address = getNode().getAddressStr();
334  }
335  return new Informer(getEchoClassCode(), getInstanceCode()
336  , address, isSelfObject());
337  }
338 
339  public static class Receiver extends EchoObject.Receiver {
340 
341  @Override
342  protected boolean onSetProperty(EchoObject eoj, short tid, byte esv,
343  EchoProperty property, boolean success) {
344  boolean ret = super.onSetProperty(eoj, tid, esv, property, success);
345  if(ret) return true;
346 
347  //switch(property.epc) {
348  //default :
349  // return false;
350  //}
351  return false;
352  }
353 
354  @Override
355  protected boolean onGetProperty(EchoObject eoj, short tid, byte esv,
356  EchoProperty property, boolean success) {
357  boolean ret = super.onGetProperty(eoj, tid, esv, property, success);
358  if(ret) return true;
359 
360  switch(property.epc) {
361  case EPC_FAULT_STATUS:
362  onGetFaultStatus(eoj, tid, esv, property, success);
363  return true;
365  onGetManufacturerCode(eoj, tid, esv, property, success);
366  return true;
368  onGetPlaceOfBusinessCode(eoj, tid, esv, property, success);
369  return true;
370  case EPC_PRODUCT_CODE:
371  onGetProductCode(eoj, tid, esv, property, success);
372  return true;
373  case EPC_SERIAL_NUMBER:
374  onGetSerialNumber(eoj, tid, esv, property, success);
375  return true;
377  onGetDateOfManufacture(eoj, tid, esv, property, success);
378  return true;
380  onGetStatusChangeAnnouncementPropertyMap(eoj, tid, esv, property, success);
381  return true;
383  onGetSetPropertyMap(eoj, tid, esv, property, success);
384  return true;
386  onGetGetPropertyMap(eoj, tid, esv, property, success);
387  return true;
388  default :
389  return false;
390  }
391  }
392 
393  @Override
394  protected boolean onInformProperty(EchoObject eoj, short tid, byte esv,
395  EchoProperty property) {
396  boolean ret = super.onInformProperty(eoj, tid, esv, property);
397  if(ret) return true;
398 
399  //switch(property.epc) {
400  //default :
401  // return false;
402  //}
403  return false;
404  }
405 
414  protected void onGetFaultStatus(EchoObject eoj, short tid, byte esv, EchoProperty property, boolean success) {}
423  protected void onGetManufacturerCode(EchoObject eoj, short tid, byte esv, EchoProperty property, boolean success) {}
432  protected void onGetPlaceOfBusinessCode(EchoObject eoj, short tid, byte esv, EchoProperty property, boolean success) {}
441  protected void onGetProductCode(EchoObject eoj, short tid, byte esv, EchoProperty property, boolean success) {}
450  protected void onGetSerialNumber(EchoObject eoj, short tid, byte esv, EchoProperty property, boolean success) {}
461  protected void onGetDateOfManufacture(EchoObject eoj, short tid, byte esv, EchoProperty property, boolean success) {}
469  protected void onGetStatusChangeAnnouncementPropertyMap(EchoObject eoj, short tid, byte esv, EchoProperty property, boolean success) {
470  if(success) {
471  byte[] properties = EchoUtils.propertyMapToProperties(property.edt);
472  for(byte p : properties) {
473 
474  }
475  }
476  }
484  protected void onGetSetPropertyMap(EchoObject eoj, short tid, byte esv, EchoProperty property, boolean success) {
485 
486  }
494  protected void onGetGetPropertyMap(EchoObject eoj, short tid, byte esv, EchoProperty property, boolean success) {
495 
496  }
497  }
498 
499  public static class Setter extends EchoObject.Setter {
500 
501  public Setter(short dstEchoClassCode, byte dstEchoInstanceCode
502  , String dstEchoAddress, boolean responseRequired) {
503  super(dstEchoClassCode, dstEchoInstanceCode
504  , dstEchoAddress, responseRequired);
505  }
506 
507  @Override
508  public Setter reqSetProperty(byte epc,
509  byte[] edt) {
510  return (Setter)super.reqSetProperty(epc, edt);
511  }
512 
513  }
514 
515  public static class Getter extends EchoObject.Getter {
516  public Getter(short dstEchoClassCode, byte dstEchoInstanceCode
517  , String dstEchoAddress) {
518  super(dstEchoClassCode, dstEchoInstanceCode
519  , dstEchoAddress);
520  }
521 
522  @Override
523  public Getter reqGetProperty(byte epc) {
524  return (Getter)super.reqGetProperty(epc);
525  }
526 
535  public Getter reqGetFaultStatus() {
536  reqGetProperty(EPC_FAULT_STATUS);
537  return this;
538  }
547  public Getter reqGetManufacturerCode() {
548  reqGetProperty(EPC_MANUFACTURER_CODE);
549  return this;
550  }
559  public Getter reqGetPlaceOfBusinessCode() {
560  reqGetProperty(EPC_PLACE_OF_BUSINESS_CODE);
561  return this;
562  }
571  public Getter reqGetProductCode() {
572  reqGetProperty(EPC_PRODUCT_CODE);
573  return this;
574  }
583  public Getter reqGetSerialNumber() {
584  reqGetProperty(EPC_SERIAL_NUMBER);
585  return this;
586  }
597  public Getter reqGetDateOfManufacture() {
598  reqGetProperty(EPC_DATE_OF_MANUFACTURE);
599  return this;
600  }
608  public Getter reqGetStatusChangeAnnouncementPropertyMap() {
610  return this;
611  }
619  public Getter reqGetSetPropertyMap() {
620  reqGetProperty(EPC_SET_PROPERTY_MAP);
621  return this;
622  }
630  public Getter reqGetGetPropertyMap() {
631  reqGetProperty(EPC_GET_PROPERTY_MAP);
632  return this;
633  }
634  }
635 
636  public static class Informer extends EchoObject.Informer {
637 
638  public Informer(short echoClassCode, byte echoInstanceCode
639  , String dstEchoAddress, boolean isSelfObject) {
640  super(echoClassCode, echoInstanceCode
641  , dstEchoAddress, isSelfObject);
642  }
643 
644  @Override
645  public Informer reqInformProperty(byte epc) {
646  return (Informer)super.reqInformProperty(epc);
647  }
648 
657  public Informer reqInformFaultStatus() {
658  reqInformProperty(EPC_FAULT_STATUS);
659  return this;
660  }
669  public Informer reqInformManufacturerCode() {
670  reqInformProperty(EPC_MANUFACTURER_CODE);
671  return this;
672  }
681  public Informer reqInformPlaceOfBusinessCode() {
682  reqInformProperty(EPC_PLACE_OF_BUSINESS_CODE);
683  return this;
684  }
693  public Informer reqInformProductCode() {
694  reqInformProperty(EPC_PRODUCT_CODE);
695  return this;
696  }
705  public Informer reqInformSerialNumber() {
706  reqInformProperty(EPC_SERIAL_NUMBER);
707  return this;
708  }
719  public Informer reqInformDateOfManufacture() {
720  reqInformProperty(EPC_DATE_OF_MANUFACTURE);
721  return this;
722  }
730  public Informer reqInformStatusChangeAnnouncementPropertyMap() {
732  return this;
733  }
741  public Informer reqInformSetPropertyMap() {
742  reqInformProperty(EPC_SET_PROPERTY_MAP);
743  return this;
744  }
752  public Informer reqInformGetPropertyMap() {
753  reqInformProperty(EPC_GET_PROPERTY_MAP);
754  return this;
755  }
756  }
757 }
final byte[] getStatusChangeAnnouncementProperties()
Definition: EchoObject.java:84
final void addStatusChangeAnnouncementProperty(byte epc)
Definition: EchoObject.java:71
final void addGetProperty(byte epc)
final void addSetProperty(byte epc)
Definition: EchoObject.java:93
synchronized boolean setProperty(EchoProperty property)
synchronized byte[] getProperty(byte epc)
synchronized boolean isValidProperty(EchoProperty property)
boolean isValidStatusChangeAnnouncementPropertyMap(byte[] edt)
final void clearStatusChangeAnnouncementProperties()
Definition: EchoObject.java:80
static final byte EPC_STATUS_CHANGE_ANNOUNCEMENT_PROPERTY_MAP
static final String MULTICAST_ADDRESS
Definition: EchoSocket.java:53
Setter set(boolean responseRequired)
abstract short getEchoClassCode()