001: /*
002: * DDS (Data Distribution Service) for JacORB
003: *
004: * Copyright (C) 2005 , Ahmed yehdih <ahmed.yehdih@gmail.com>, fouad
005: * allaoui <fouad.allaoui@gmail.com>, Didier Donsez (didier.donsez@ieee.org)
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Library General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU Library General Public License for more details.
016: *
017: * You should have received a copy of the GNU Library General Public
018: * License along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
020: * 02111-1307, USA.
021: *
022: * Coontact: Ahmed yehdih <ahmed.yehdih@gmail.com>, fouad allaoui
023: * <fouad.allaoui@gmail.com>, Didier Donsez (didier.donsez@ieee.org)
024: * Contributor(s)
025: *
026: **/
027: package demo.dds.dcps.foosample;
028:
029: import java.util.Iterator;
030: import java.util.Vector;
031:
032: import org.jacorb.dds.SubscriberImpl;
033: import org.omg.dds.DataReaderListener;
034: import org.omg.dds.DataReaderQos;
035: import org.omg.dds.DataReaderQosHolder;
036: import org.omg.dds.Duration_t;
037: import org.omg.dds.InstanceHandleSeqHolder;
038: import org.omg.dds.LivelinessChangedStatus;
039: import org.omg.dds.PublicationBuiltinTopicDataHolder;
040: import org.omg.dds.QueryCondition;
041: import org.omg.dds.RETCODE_OK;
042: import org.omg.dds.ReadCondition;
043: import org.omg.dds.RequestedDeadlineMissedStatus;
044: import org.omg.dds.RequestedIncompatibleQosStatus;
045: import org.omg.dds.SampleInfoHolder;
046: import org.omg.dds.SampleInfoSeqHolder;
047: import org.omg.dds.SampleLostStatus;
048: import org.omg.dds.SampleRejectedStatus;
049: import org.omg.dds.StatusCondition;
050: import org.omg.dds.Subscriber;
051: import org.omg.dds.SubscriptionMatchStatus;
052: import org.omg.dds.Topic;
053: import org.omg.dds.TopicDescription;
054:
055: /**
056: * DataReader is an abstract class. It must be specialized for each particular application
057: * data-type . The additional methods that must be defined in the auto-generated class for
058: * a hypothetical application type “Foo” .
059: */
060: public class FooDataReaderImpl extends FooDataReaderPOA {
061:
062: // represent the data stockage space of a dataReader
063: private Vector Vector_Foo;
064:
065: private DataReaderQos qos;
066:
067: private DataReaderListener a_listener;
068:
069: private Subscriber SubParent;
070:
071: private Topic topic;
072:
073: private org.omg.CORBA.ORB orb;
074:
075: private org.omg.PortableServer.POA poa;
076:
077: private DataReaderListener _listener;
078:
079: /**
080: * @param qos
081: * @param a_listener
082: * @param subParent
083: * @param topic_name
084: */
085: public FooDataReaderImpl(DataReaderQos qos,
086: DataReaderListener a_listener, Subscriber subParent,
087: Topic topic, org.omg.CORBA.ORB orb,
088: org.omg.PortableServer.POA poa) {
089: this .qos = qos;
090: this .a_listener = a_listener;
091: SubParent = subParent;
092: this .topic = topic;
093: Vector_Foo = new Vector();
094: this .orb = orb;
095: this .poa = poa;
096: }
097:
098: /**
099: * @param received_data
100: * @param info_seq
101: * @param max_samples
102: * @param sample_states
103: * @param view_states
104: * @param instance_states
105: * @return
106: */
107: public int read(FooSeqHolder received_data,
108: SampleInfoSeqHolder info_seq, int max_samples,
109: int sample_states, int view_states, int instance_states) {
110:
111: try {
112: int i = 0;
113: Foo tab[] = new Foo[getVector_Foo().size()];
114: Iterator it = getVector_Foo().iterator();
115:
116: while (it.hasNext()) {
117: tab[i] = (Foo) it.next();
118: i++;
119: }
120: received_data.value = tab;
121: } catch (Exception e) {
122: System.out.println("Error e = " + e);
123: e.printStackTrace();
124: }
125:
126: return RETCODE_OK.value;
127: }
128:
129: /**
130: * @param received_data
131: * @param info_seq
132: * @param max_samples
133: * @param sample_states
134: * @param view_states
135: * @param instance_states
136: * @return
137: */
138: public int take(FooSeqHolder received_data,
139: SampleInfoSeqHolder info_seq, int max_samples,
140: int sample_states, int view_states, int instance_states) {
141:
142: int i = 0;
143: Foo tab[] = new Foo[getVector_Foo().size()];
144: Iterator it = getVector_Foo().iterator();
145:
146: while (it.hasNext()) {
147: tab[i] = (Foo) it.next();
148: i++;
149: }
150: received_data.value = tab;
151: // remove all element from the vector
152: clear();
153:
154: return RETCODE_OK.value;
155: }
156:
157: /**
158: * Not Implemented
159: */
160: public int read_w_condition(FooSeqHolder received_data,
161: SampleInfoSeqHolder info_seq, int max_samples,
162: ReadCondition a_condition) {
163:
164: return 0;
165: }
166:
167: /**
168: * Not Implemented
169: */
170: public int take_w_condition(FooSeqHolder received_data,
171: SampleInfoSeqHolder info_seq, int max_samples,
172: ReadCondition a_condition) {
173: return 0;
174: }
175:
176: /**
177: * Not Implemented
178: */
179: public int read_next_sample(FooHolder received_data,
180: SampleInfoHolder sample_info) {
181: return 0;
182: }
183:
184: /**
185: * Not Implemented
186: */
187: public int take_next_sample(FooHolder received_data,
188: SampleInfoHolder sample_info) {
189: return 0;
190: }
191:
192: /**
193: * Not Implemented
194: */
195: public int read_instance(FooSeqHolder received_data,
196: SampleInfoSeqHolder info_seq, int max_samples,
197: int a_handle, int sample_states, int view_states,
198: int instance_states) {
199: return 0;
200: }
201:
202: /**
203: * Not Implemented
204: */
205: public int take_instance(FooSeqHolder received_data,
206: SampleInfoSeqHolder info_seq, int max_samples,
207: int a_handle, int sample_states, int view_states,
208: int instance_states) {
209: return 0;
210: }
211:
212: /**
213: * Not Implemented
214: */
215: public int read_next_instance(FooSeqHolder received_data,
216: SampleInfoSeqHolder info_seq, int max_samples,
217: int a_handle, int sample_states, int view_states,
218: int instance_states) {
219: return 0;
220: }
221:
222: /**
223: * Not Implemented
224: */
225: public int take_next_instance(FooSeqHolder received_data,
226: SampleInfoSeqHolder info_seq, int max_samples,
227: int a_handle, int sample_states, int view_states,
228: int instance_states) {
229: return 0;
230: }
231:
232: /**
233: * Not Implemented
234: */
235: public int read_next_instance_w_condition(
236: FooSeqHolder received_data, SampleInfoSeqHolder info_seq,
237: int max_samples, int a_handle, ReadCondition a_condition) {
238: return 0;
239: }
240:
241: /**
242: * Not Implemented
243: */
244: public int take_next_instance_w_condition(
245: FooSeqHolder received_data, SampleInfoSeqHolder info_seq,
246: int max_samples, int a_handle, ReadCondition a_condition) {
247: return 0;
248: }
249:
250: /**
251: * Not Implemented
252: */
253: public int return_loan(FooSeqHolder received_data,
254: SampleInfoSeqHolder info_seq) {
255: return 0;
256: }
257:
258: /**
259: * Not Implemented
260: */
261: public int get_key_value(FooHolder key_holder, int handle) {
262: return 0;
263: }
264:
265: /**
266: * Not Implemented
267: */
268: public ReadCondition create_readcondition(int sample_states,
269: int view_states, int instance_states) {
270: return null;
271: }
272:
273: /**
274: * Not Implemented
275: */
276: public QueryCondition create_querycondition(int sample_states,
277: int view_states, int instance_states,
278: String query_expression, String[] query_parameters) {
279: return null;
280: }
281:
282: /**
283: * Not Implemented
284: */
285: public int delete_readcondition(ReadCondition a_condition) {
286: return 0;
287: }
288:
289: /**
290: * Not Implemented
291: */
292: public int delete_contained_entities() {
293: return 0;
294: }
295:
296: /**
297: * Not Implemented
298: */
299: public int set_qos(DataReaderQos qos) {
300: return 0;
301: }
302:
303: /**
304: * Not Implemented
305: */
306: public void get_qos(DataReaderQosHolder qos) {
307:
308: }
309:
310: /**
311: * @param a_listener
312: * @param mask
313: * @return
314: */
315: public int set_listener(org.omg.dds.DataReaderListener a_listener,
316: int mask) {
317:
318: try {
319: this ._listener = a_listener;
320: } catch (Exception e) {
321: System.out.println(" Exception e :" + e);
322: e.printStackTrace();
323: }
324:
325: return 0;
326: }
327:
328: /**
329: * @return _listener
330: */
331: public DataReaderListener get_listener() {
332: return _listener;
333: }
334:
335: /**
336: * @return topic
337: */
338: public TopicDescription get_topicdescription() {
339: return topic;
340: }
341:
342: /**
343: * Not Implemented
344: */
345: public Subscriber get_subscriber() {
346: return null;
347: }
348:
349: /**
350: * Not Implemented
351: */
352: public SampleRejectedStatus get_sample_rejected_status() {
353: return null;
354: }
355:
356: /**
357: * Not Implemented
358: */
359: public LivelinessChangedStatus get_liveliness_changed_status() {
360: return null;
361: }
362:
363: /**
364: * Not Implemented
365: */
366: public RequestedDeadlineMissedStatus get_requested_deadline_missed_status() {
367: return null;
368: }
369:
370: /**
371: * Not Implemented
372: */
373: public RequestedIncompatibleQosStatus get_requested_incompatible_qos_status() {
374: return null;
375: }
376:
377: /**
378: * Not Implemented
379: */
380: public SubscriptionMatchStatus get_subscription_match_status() {
381: return null;
382: }
383:
384: /**
385: * Not Implemented
386: */
387: public SampleLostStatus get_sample_lost_status() {
388: return null;
389: }
390:
391: /**
392: * Not Implemented
393: */
394: public int wait_for_historical_data(Duration_t max_wait) {
395: return 0;
396: }
397:
398: /**
399: * Not Implemented
400: */
401: public int get_matched_publications(
402: InstanceHandleSeqHolder publication_handles) {
403: return 0;
404: }
405:
406: /**
407: * Not Implemented
408: */
409: public int get_matched_publication_data(
410: PublicationBuiltinTopicDataHolder publication_data,
411: int publication_handle) {
412: return 0;
413: }
414:
415: /**
416: * Not Implemented
417: */
418: public int enable() {
419: return 0;
420: }
421:
422: /**
423: * Not Implemented
424: */
425: public StatusCondition get_statuscondition() {
426: return null;
427: }
428:
429: /**
430: * Not Implemented
431: */
432: public int get_status_changes() {
433: return 0;
434: }
435:
436: /**
437: * @param arg0
438: * @return
439: */
440: public boolean add(Object arg0) {
441: return Vector_Foo.add(arg0);
442: }
443:
444: /**
445: *
446: */
447: public void clear() {
448: Vector_Foo.clear();
449: }
450:
451: /**
452: * @param arg0
453: * @return
454: */
455: public boolean remove(Object arg0) {
456: return Vector_Foo.remove(arg0);
457: }
458:
459: /**
460: * @return Returns the vector_Foo.
461: */
462: public Vector getVector_Foo() {
463: return Vector_Foo;
464: }
465:
466: /**
467: * @return Returns the a_listener.
468: */
469: public DataReaderListener getA_listener() {
470: return a_listener;
471: }
472:
473: /**
474: * @return Returns the qos.
475: */
476: public DataReaderQos getQos() {
477: return qos;
478: }
479:
480: /**
481: * @return Returns the subParent.
482: */
483: public Subscriber getSubParent() {
484: return SubParent;
485: }
486:
487: /**
488: * take instance of Foo from suscriber
489: */
490: public void take_instance_from_subscriber() {
491: try {
492: SubscriberImpl Subscriber_Parent = (SubscriberImpl) _poa()
493: .reference_to_servant(getSubParent());
494: add((Foo) Subscriber_Parent.getInstance());
495: }
496:
497: catch (Exception e) {
498:
499: }
500:
501: }
502:
503: }
|