]> rtime.felk.cvut.cz Git - orte/eurobot.git/blob - orte/java/src/org/ocera/orte/DomainMgr.java
13f01facffaa33b1bbae1511a7915a7ffdf7d888
[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) && (this.props == null || this.props.destroy())) return true;
77             System.out.println(":j!: ORTEDomainMgrDestroy() fault..");
78             return false;
79           }
80   
81
82   /* ****************************************************************** *
83    *                                                                    *
84    *                         native methods                             *
85    *                                                                    *
86    * ****************************************************************** */
87   /**
88    * jORTEDomainMgrCreate - creates default Manager
89    * @param handle of the domain
90    * @return handle of the Manager
91    **/
92    private native
93    long jORTEDomainDefaultMgrCreate(int dhandle,boolean suspend);
94
95
96   /**
97    * jORTEDomainMgrCreate - creates the Manager
98    * @param handle of the domain
99    * @param handle of the domain properties
100    * @param handle of the domain events
101    * @return handle of the Manager
102    **/
103    private native
104    long jORTEDomainMgrCreate(int dhandle,
105                              long propsHandle,
106                              long eventsHandle,
107                              DomainEvents ev,
108                              boolean suspend);
109
110   /**
111    * jORTEDomainMgrDestroy - destroy manager object
112    * @param hadle of the domain
113    * @return if some error occures return False, otherwise True
114    **/
115    private native
116    boolean jORTEDomainMgrDestroy(long dhandle);  
117         
118 }