]> rtime.felk.cvut.cz Git - orte/eurobot.git/blob - orte/java/src/org/ocera/orte/DomainMgr.java
JORTE: free() domain events
[orte/eurobot.git] / orte / java / src / org / ocera / orte / DomainMgr.java
1 /* DomainMgr.java */
2
3 /**
4  * Class DomainMgr provides methods for work with the ORTE manager domain.
5  *
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
10  * @version 0.1
11  *
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.
16  *
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.
21  *
22  */
23
24 package org.ocera.orte;
25 import org.ocera.orte.types.DomainEvents;
26 import org.ocera.orte.types.DomainProp;
27 import org.ocera.orte.types.ORTEConstant;
28
29
30 public class DomainMgr extends Domain 
31 {
32
33    /**
34         * Default constructor. Creates default Manager domain.
35         * (domain = ORTE_DEFAULT_DOMAI, suspended thread = false)
36         **/
37    public DomainMgr()
38    {
39          super();
40      handle = jORTEDomainDefaultMgrCreate(ORTEConstant.ORTE_DEFAULT_DOMAIN,
41                                               false);
42    }
43
44
45    /**
46         * User constructor. Creates manager domain with user parameters.
47         * @param given domain
48         * @param domain properties
49         * @param domain events
50         * @param specifies whether threads of thiss manager should be started as well (False) or stay suspended (True) 
51         **/
52     /* TODO dodelat instance 'props', 'events' */
53     public DomainMgr(int domain,
54                          DomainProp props,
55                          DomainEvents events,
56                          boolean suspend)
57     {
58      super();
59      this.props = props;
60      this.events = events;
61      this.handle = jORTEDomainMgrCreate(domain,
62                                         props==null ? 0 : this.props.getHandle(),
63                                         events==null ? 0 : this.events.getHandle(),
64                                         this.events,
65                                         suspend);
66     }
67      
68          /**
69           * destroy - destroy manager object
70           * @return boolean: False if bad publication handle, True if  succesful
71           */
72       @Override
73           public
74           boolean destroy()
75           {
76             if(jORTEDomainMgrDestroy(this.handle)
77                         && (this.props == null || this.props.destroy())
78                         && (this.events == null || this.events.destroy())) return true;
79             System.out.println(":j!: ORTEDomainMgrDestroy() fault..");
80             return false;
81           }
82   
83
84   /* ****************************************************************** *
85    *                                                                    *
86    *                         native methods                             *
87    *                                                                    *
88    * ****************************************************************** */
89   /**
90    * jORTEDomainMgrCreate - creates default Manager
91    * @param handle of the domain
92    * @return handle of the Manager
93    **/
94    private native
95    long jORTEDomainDefaultMgrCreate(int dhandle,boolean suspend);
96
97
98   /**
99    * jORTEDomainMgrCreate - creates the Manager
100    * @param handle of the domain
101    * @param handle of the domain properties
102    * @param handle of the domain events
103    * @return handle of the Manager
104    **/
105    private native
106    long jORTEDomainMgrCreate(int dhandle,
107                              long propsHandle,
108                              long eventsHandle,
109                              DomainEvents ev,
110                              boolean suspend);
111
112   /**
113    * jORTEDomainMgrDestroy - destroy manager object
114    * @param hadle of the domain
115    * @return if some error occures return False, otherwise True
116    **/
117    private native
118    boolean jORTEDomainMgrDestroy(long dhandle);  
119         
120 }