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)
54 this.handle = jORTEDomainAppCreate(domain,
55 ps==null ? 0 : this.props.getHandle(),
56 ev==null ? 0 : this.events.getHandle(),
59 /* TODO osetrit neuspesne vytvoreni domeny */
60 if(this.handle == 0) System.out.println(":j!: zero domain handle! ..");
61 else System.out.println(":j: application domain created..");
65 * Destroy the Application Domain.
68 public boolean destroy()
70 if(destroyAllRegTypes() && jORTEDomainAppDestroy(this.handle) && (this.props == null || this.props.destroy())) return true;
71 System.out.println(":j!: ORTEDomainAppDestroy() fault..");
77 * Register new data type.
78 * @param Name of the new type.
79 * @param Max length of the input buffer.
80 * @return True - registration Ok, False - registration fault.
83 boolean regNewDataType(String name,
86 int b = jORTETypeRegisterAdd(this.handle,
89 if (b == ORTEConstant.ORTE_BAD_HANDLE)
91 System.out.println(":!j: regNewDataType() failed! [bad domain handle]");
94 if (b == ORTEConstant.ORTE_OK)
96 System.out.println(":j: type: '" + name + "' successfully registered..");
104 * Destroys all previous registered data types.
105 * @return True - registration Ok, False - destroying fault.
108 boolean destroyAllRegTypes()
110 if (jORTETypeRegisterDestroyAll(this.handle)) return true;
116 * Creates a new Subscription.
118 * @param Subscription properties.
119 * @param Length of output buffer.
120 * @param Callback instance.
121 * @return Handle to the new created Subscription.
124 Subscription createSubscription(SubsProp subsProp,
125 MessageData instance,
126 SubscriptionCallback subsCallback)
128 Subscription s = new Subscription(this,
137 * Creates a new Publication.
139 * @param Instance of MessageData (which data will be send).
140 * @param Time parameter, which defines how long are publicated data valid.
141 * @param The importance of this Publication (its rating).
142 * @return Handle to the new created Publication.
145 Publication createPublication(PublProp publProp,
146 MessageData instance)
148 //System.out.println(":j: vytvarim publikaci pro DataType: " + instance.getType());
149 Publication p = new Publication(this,
156 /* ****************************************************************** *
160 * ****************************************************************** */
163 * jORTEDomainAppCreate - creates an default application object within given
164 * domain, returns handle to created object (from C environment),
165 * NULL in case of any error.
168 * @param domain given domain
169 * @return addres value (from C environment) of the created domain
171 private native long jORTEDomainDefaultAppCreate(int domain,boolean suspend);
175 * jORTEDomainAppCreate - creates an application object within given
176 * domain, returns handle to created object (from C environment),
177 * NULL in case of any error.
180 * @param domain given domain
181 * @param handler for C pointer to ORTEDomainProps
182 * @param handler for C pointer to ORTEDomainEvents
183 * @param suspended specifies whether threads of this application should be started as well (False) or stay suspended (True)
184 * @return addres value (from C environment) of the created domain
188 long jORTEDomainAppCreate(int domain,
196 * jORTEDomainADestroy - destroys all application objects in specified
197 * domain, returns False if some error occures otherwise returns True.
200 * @param jp_domhandle handler to domain
201 * @return boolean value, False when some error occures, otherwise True
204 boolean jORTEDomainAppDestroy(long dhandle);
208 * jORTETypeRegisterAdd - register new data type.
211 * @param dhandle handler to domain
218 int jORTETypeRegisterAdd(long dhandle,
224 * jORTETypeRegisterDestroyAll - destroys all previous registered data types.
227 * @param dhandle handler to domain
228 * @return boolean value, False when some error occures, otherwise True
231 boolean jORTETypeRegisterDestroyAll(long dhandle);