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 org.ocera.orte.types.*;
28 public class DomainApp extends Domain
32 * Default constructor. Creates an Application Domain with default parameters.
33 * (domain = ORTE_DEFAULT_DOMAIN, suspended thread = false)
38 // this.handle =jORTEDomainDefaultAppCreate(ORTEConstant.ORTE_DEFAULT_DOMAIN,true); - uspane vlakno po startu
39 this.handle = jORTEDomainDefaultAppCreate(ORTEConstant.ORTE_DEFAULT_DOMAIN,false);
40 if(this.handle == 0) System.out.println(":j!: zero domain handle! ..");
41 else System.out.println(":j: application domain created..");
46 * User defined constructor. For creating an Application Domain with your parameters.
48 /** TODO dodelat objekty 'props', 'events' */
49 public DomainApp(int domain, DomainProp ps, DomainEvents ev, boolean suspend)
51 super(); // set Default Domain Properties
53 this.props = DomainProp.defaultPropsCreate();
65 this.handle = jORTEDomainAppCreate(domain,ps.handle,ev.getHandle(),ev,suspend);
66 /* TODO osetrit neuspesne vytvoreni domeny */
67 if(this.handle == 0) System.out.println(":j!: zero domain handle! ..");
68 else System.out.println(":j: application domain created..");
72 * Destroy the Application Domain.
74 public boolean destroy()
76 if(!destroyAllRegTypes()) System.out.println(":j!: destroyAllRegTypes fault!");
77 if(!jORTEDomainAppDestroy(this.handle) || !this.props.destroy()) {
78 System.out.println(":j!: ORTEDomainADestroy fault!");
87 * Register new data type.
88 * @param Name of the new type.
89 * @param Max length of the input buffer.
90 * @return True - registration Ok, False - registration fault.
93 boolean regNewDataType(String name,
96 int b = jORTETypeRegisterAdd(this.handle,
99 if (b == ORTEConstant.ORTE_BAD_HANDLE)
101 System.out.println(":!j: regNewDataType() failed! [bad domain handle]");
104 if (b == ORTEConstant.ORTE_OK)
106 System.out.println(":j: type: '" + name + "' successfully registered..");
114 * Destroys all previous registered data types.
115 * @return True - registration Ok, False - destroying fault.
118 boolean destroyAllRegTypes()
120 if (jORTETypeRegisterDestroyAll(this.handle)) return true;
126 * Creates a new Subscription.
128 * @param Subscription properties.
129 * @param Length of output buffer.
130 * @param Callback instance.
131 * @return Handle to the new created Subscription.
134 Subscription createSubscription(SubsProp subsProp,
135 MessageData instance,
136 SubscriptionCallback subsCallback)
138 Subscription s = new Subscription(this,
147 * Creates a new Publication.
149 * @param Instance of MessageData (which data will be send).
150 * @param Time parameter, which defines how long are publicated data valid.
151 * @param The importance of this Publication (its rating).
152 * @return Handle to the new created Publication.
155 Publication createPublication(PublProp publProp,
156 MessageData instance)
158 //System.out.println(":j: vytvarim publikaci pro DataType: " + instance.getType());
159 Publication p = new Publication(this,
166 /* ****************************************************************** *
170 * ****************************************************************** */
173 * jORTEDomainAppCreate - creates an default application object within given
174 * domain, returns handle to created object (from C environment),
175 * NULL in case of any error.
178 * @param domain given domain
179 * @return addres value (from C environment) of the created domain
181 private static native long jORTEDomainDefaultAppCreate(int domain,boolean suspend);
185 * jORTEDomainAppCreate - creates an application object within given
186 * domain, returns handle to created object (from C environment),
187 * NULL in case of any error.
190 * @param domain given domain
191 * @param handler for C pointer to ORTEDomainProps
192 * @param handler for C pointer to ORTEDomainEvents
193 * @param suspended specifies whether threads of this application should be started as well (False) or stay suspended (True)
194 * @return addres value (from C environment) of the created domain
197 private static native
198 long jORTEDomainAppCreate(int domain,
206 * jORTEDomainADestroy - destroys all application objects in specified
207 * domain, returns False if some error occures otherwise returns True.
210 * @param jp_domhandle handler to domain
211 * @return boolean value, False when some error occures, otherwise True
213 private static native
214 boolean jORTEDomainAppDestroy(long dhandle);
218 * jORTETypeRegisterAdd - register new data type.
221 * @param dhandle handler to domain
227 private static native
228 int jORTETypeRegisterAdd(long dhandle,
234 * jORTETypeRegisterDestroyAll - destroys all previous registered data types.
237 * @param dhandle handler to domain
238 * @return boolean value, False when some error occures, otherwise True
240 private static native
241 boolean jORTETypeRegisterDestroyAll(long dhandle);