1 /* Subscription.java */
4 * Class Subscription provides methods for creating and working
5 * with the ORTE subscribtion.
7 * @author Lukas Pokorny (lukas_pokorny@centrum.cz)
8 * @author CTU FEE Prague - Department of Control Engineering (dce.felk.cvut.cz)
9 * @author Project ORTE - OCERA Real Time Ethernet (www.ocera.org)
10 * @author dedication to Kj
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
25 package org.ocera.orte;
26 import java.nio.ByteBuffer;
27 import java.nio.ByteOrder;
29 import org.ocera.orte.types.*;
32 public class Subscription {
35 private long callbackContextHandle = 0;
38 * Get Subscription's handle.
39 * @return Handle of the subscription.
41 public long getHandle()
50 /* PROC protected??? - aby sel volat jen z tridy Domain */
51 protected Subscription(Domain appDomain,
54 SubscriptionCallback subsCallback)
56 this.handle = jORTESubscriptionCreate(appDomain.handle,
60 subsProp.getTypeName(),
62 message.getBuffer().order().equals(ByteOrder.BIG_ENDIAN) ? 0 : 1,
64 subsProp.getDeadline(),
65 subsProp.getMinSeparation(),
68 subsProp.getMulticastIPAddr());
72 * Removes a Subscription.
73 * @return False if bad Publication handle, True if succesful
78 /* TODO vyradit vypis na nasledujici radce */
79 System.out.println(":j: subscription destroy called..");
80 // destroy subscription
81 if(!jORTESubscriptionDestroy(this.handle))
83 System.out.println(":j!: subscription destroy fault!");
86 System.out.println(":j: subscription destroy successfull..");
92 * Get Subscription properties.
93 * @return Subscription properties.
95 public SubsProp getProperties()
97 SubsProp sp = new SubsProp();
98 sp = jORTESubscriptionPropertiesGet(this.handle);
103 * Set Subscription properties.
104 * @return True - setting new properties Ok, False - setting new properties fault.
106 public boolean setProperties(SubsProp sp)
110 // modify SubsProp object - sp
111 b = jORTESubscriptionPropertiesSet(this.handle, sp);
114 System.out.println(":j!: set SubsProp failed! (bad Subs. handle)");
122 * Get Subscription status.
123 * @return Status of Subscription.
125 public Status getStatus()
127 Status ss = new Status();
128 ss = jORTESubscriptionGetStatus(this.handle);
134 * Waits for given number of publications.
135 * @param Time how long to wait.
136 * @param Number of retries if specified number of publications not reached.
137 * @param Desired number of publications.
138 * @return ORTE_OK if succesful, ORTE_BAD_HANDLE if bad subscription handle,
139 * ORTE_TIMEOUT if number of retries has been exhausted.
141 public int waitForPublications(NtpTime wait,
146 i = jORTESubscriptionWaitForPublications(this.handle,
155 * @param Time how long to wait.
156 * @param Number of retries if specified number of publications not reached.
157 * @param Desired number of publications.
158 * @return ORTE_OK if succesful, ORTE_BAD_HANDLE if bad subscription handle,
159 * ORTE_TIMEOUT if number of retries has been exhausted.
161 public boolean pull(long subsHandle)
163 int b = jORTESubscriptionPull(subsHandle);
164 if (b == ORTEConstant.ORTE_BAD_HANDLE)
166 System.out.println(":j!: method pull failed [bad subsHandle]!");
172 /* TODO - dodelat!! */
173 public void patternCreate()
175 /* TODO - dodelat!! */
176 public void patternRemove()
178 /* TODO - dodelat!! */
179 public void patternDelete()
184 /* ****************************************************************** *
188 * ****************************************************************** */
191 long jORTESubscriptionCreate(long appDomainHandle,
192 int subsmode, /*! union */
193 int substype, /*! union */
200 NtpTime minSeparation,
201 SubscriptionCallback cb,
203 long multicastIPAddress);
206 boolean jORTESubscriptionDestroy(long subsHandle);
209 SubsProp jORTESubscriptionPropertiesGet(long subsHandle);
212 boolean jORTESubscriptionPropertiesSet(long subsHandle, SubsProp subProps);
215 Status jORTESubscriptionGetStatus(long subsHandle);
218 int jORTESubscriptionWaitForPublications(long subsHandle,
221 long noPublications);
223 int jORTESubscriptionPull(long subsHandle);