4 * Class DomainApp provides methods for work with the ORTE application domain.
6 * @author Lukas Pokorny (lukas_pokorny@centrum.cz)
7 * @author CTU FEE Prague - Department of Control Engineering (dce.felk.cvut.cz)
8 * @author Project ORTE - OCERA Real Time Ethernet (www.ocera.org)
9 * @author dedication to Kj
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
24 package org.ocera.orte;
25 import java.nio.ByteBuffer;
27 import org.ocera.orte.types.*;
30 public class DomainApp extends Domain
34 * Default constructor. Creates an Application Domain with default parameters.
35 * (domain = ORTE_DEFAULT_DOMAIN, suspended thread = false)
40 // this.handle =jORTEDomainDefaultAppCreate(ORTEConstant.ORTE_DEFAULT_DOMAIN,true); - uspane vlakno po startu
41 this.handle = jORTEDomainDefaultAppCreate(ORTEConstant.ORTE_DEFAULT_DOMAIN,false);
42 if(this.handle == 0) System.out.println(":j!: zero domain handle! ..");
43 else System.out.println(":j: application domain created..");
48 * User defined constructor. For creating an Application Domain with your parameters.
50 /** TODO dodelat objekty 'props', 'events' */
51 public DomainApp(int domain, DomainProp ps, DomainEvents ev, boolean suspend)
56 this.handle = jORTEDomainAppCreate(domain,
57 ps==null ? 0 : this.props.getHandle(),
58 ev==null ? 0 : this.events.getHandle(),
61 /* TODO osetrit neuspesne vytvoreni domeny */
62 if(this.handle == 0) System.out.println(":j!: zero domain handle! ..");
63 else System.out.println(":j: application domain created..");
67 * Destroy the Application Domain.
70 public boolean destroy()
72 if(destroyAllRegTypes() && jORTEDomainAppDestroy(this.handle)
73 && (this.props == null || this.props.destroy())
74 && (this.events == null || this.events.destroy())) return true;
75 System.out.println(":j!: ORTEDomainAppDestroy() fault..");
81 * Register new data type.
82 * @param Name of the new type.
83 * @param Max length of the input buffer.
84 * @return True - registration Ok, False - registration fault.
87 boolean regNewDataType(String name,
91 int b = jORTETypeRegisterAdd(this.handle,
95 if (b == ORTEConstant.ORTE_BAD_HANDLE)
97 System.out.println(":!j: regNewDataType() failed! [bad domain handle]");
100 if (b == ORTEConstant.ORTE_OK)
102 System.out.println(":j: type: '" + name + "' successfully registered..");
110 * Destroys all previous registered data types.
111 * @return True - registration Ok, False - destroying fault.
114 boolean destroyAllRegTypes()
116 if (jORTETypeRegisterDestroyAll(this.handle)) return true;
122 * Creates a new Subscription.
124 * @param Subscription properties.
125 * @param Length of output buffer.
126 * @param Callback instance.
127 * @return Handle to the new created Subscription.
130 Subscription createSubscription(SubsProp subsProp,
131 MessageData instance,
132 SubscriptionCallback subsCallback)
134 Subscription s = new Subscription(this,
143 * Creates a new Publication.
145 * @param Instance of MessageData (which data will be send).
146 * @param Time parameter, which defines how long are publicated data valid.
147 * @param The importance of this Publication (its rating).
148 * @return Handle to the new created Publication.
151 Publication createPublication(PublProp publProp,
152 MessageData instance)
154 //System.out.println(":j: vytvarim publikaci pro DataType: " + instance.getType());
155 Publication p = new Publication(this,
162 /* ****************************************************************** *
166 * ****************************************************************** */
169 * jORTEDomainAppCreate - creates an default application object within given
170 * domain, returns handle to created object (from C environment),
171 * NULL in case of any error.
174 * @param domain given domain
175 * @return addres value (from C environment) of the created domain
177 private native long jORTEDomainDefaultAppCreate(int domain,boolean suspend);
181 * jORTEDomainAppCreate - creates an application object within given
182 * domain, returns handle to created object (from C environment),
183 * NULL in case of any error.
186 * @param domain given domain
187 * @param handler for C pointer to ORTEDomainProps
188 * @param handler for C pointer to ORTEDomainEvents
189 * @param suspended specifies whether threads of this application should be started as well (False) or stay suspended (True)
190 * @return addres value (from C environment) of the created domain
194 long jORTEDomainAppCreate(int domain,
202 * jORTEDomainADestroy - destroys all application objects in specified
203 * domain, returns False if some error occures otherwise returns True.
206 * @param jp_domhandle handler to domain
207 * @return boolean value, False when some error occures, otherwise True
210 boolean jORTEDomainAppDestroy(long dhandle);
214 * jORTETypeRegisterAdd - register new data type.
217 * @param dhandle handler to domain
224 int jORTETypeRegisterAdd(long dhandle,
231 * jORTETypeRegisterDestroyAll - destroys all previous registered data types.
234 * @param dhandle handler to domain
235 * @return boolean value, False when some error occures, otherwise True
238 boolean jORTETypeRegisterDestroyAll(long dhandle);