summaryrefslogtreecommitdiffstats
path: root/org.rtems.cdt.toolchain/src/org/rtems/cdt/toolchain/RtemsManagerRelocationLinkHandler.java
blob: 5d41b60c8666fde37ae81796fdc275f2981240f8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package org.rtems.cdt.toolchain;

import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;

import org.eclipse.cdt.managedbuilder.core.IBuildObject;
import org.eclipse.cdt.managedbuilder.core.IHoldsOptions;
import org.eclipse.cdt.managedbuilder.core.IManagedOptionValueHandler;
import org.eclipse.cdt.managedbuilder.core.IOption;

public class RtemsManagerRelocationLinkHandler implements 
                                                   IManagedOptionValueHandler { 
  private static HashMap<String, Boolean> defaultMgrStatusMap = new HashMap<String, Boolean>(32);
  private static HashMap<String, Boolean> mgrStatusMap = new HashMap<String, Boolean>(32);
  private static HashMap<String, String> no_mgr_relMap = new HashMap<String, String>(32);
  
  private static String bspLibDir;
  private static String relocationLinkObjs;

  static {
    bspLibDir = " " + RtemsEnvironmentVariableSupplier.
                     getRtemsInstallBspLibDirectory().toPortableString() + "/";
    
    defaultMgrStatusMap.put("barrier",    Boolean.FALSE);           
    defaultMgrStatusMap.put("console",    Boolean.TRUE);
    defaultMgrStatusMap.put("dpmem",      Boolean.FALSE);
    defaultMgrStatusMap.put("event",      Boolean.FALSE);
    defaultMgrStatusMap.put("ext",        Boolean.FALSE);
    defaultMgrStatusMap.put("filesystem", Boolean.FALSE);
    defaultMgrStatusMap.put("io",         Boolean.TRUE);
    defaultMgrStatusMap.put("mp",         Boolean.FALSE);
    defaultMgrStatusMap.put("msg",        Boolean.FALSE);
    defaultMgrStatusMap.put("part",       Boolean.FALSE);
    defaultMgrStatusMap.put("region",     Boolean.FALSE);
    defaultMgrStatusMap.put("rtmon",      Boolean.FALSE);
    defaultMgrStatusMap.put("sem",        Boolean.FALSE);
    defaultMgrStatusMap.put("signal",     Boolean.FALSE);
    defaultMgrStatusMap.put("timer",      Boolean.FALSE);
    
    no_mgr_relMap.put("barrier"   , "no-barrier.rel");    
    no_mgr_relMap.put("console"   , "no-console.rel");
    no_mgr_relMap.put("dpmem"     , "no-dpmem.rel");
    no_mgr_relMap.put("event"     , "no-event.rel");
    no_mgr_relMap.put("ext"       , "no-ext.rel");
    no_mgr_relMap.put("filesystem", "no-filesystem.rel");
    no_mgr_relMap.put("io"        , "no-io.rel");
    no_mgr_relMap.put("mp"        , "no-mp.rel");
    no_mgr_relMap.put("msg"       , "no-msg.rel");
    no_mgr_relMap.put("part"      , "no-part.rel");
    no_mgr_relMap.put("region"    , "no-region.rel");
    no_mgr_relMap.put("rtmon"     , "no-rtmon.rel");
    no_mgr_relMap.put("sem"       , "no-sem.rel");
    no_mgr_relMap.put("signal"    , "no-signal.rel");
    no_mgr_relMap.put("timer"     , "no-timer.rel");
  }
  
  public RtemsManagerRelocationLinkHandler() {
  }
  
  /**
   * @return the relocationLinkObjs
   */
  public static synchronized String getRelocationLinkObjs() {
    return relocationLinkObjs;
  }
 
  private static synchronized void updateRelocationLink(String selectedMgrId, 
                                                          Boolean enabled) {
    StringBuilder rel = new StringBuilder(1024); // relocation link builder
    mgrStatusMap.put(selectedMgrId, enabled);
    
    for(Iterator<Map.Entry<String, Boolean>> 
        i = mgrStatusMap.entrySet().iterator(); i.hasNext(); ) {
      Map.Entry<String, Boolean> entry = (Map.Entry<String, Boolean>) i.next();
      
      String mgrId = (String)entry.getKey();
      Boolean mgrEnabled = (Boolean) entry.getValue();
      
      if (!mgrEnabled.booleanValue()) {
        rel = rel.append(bspLibDir).append( no_mgr_relMap.get(mgrId) );
      }
    }
    
    relocationLinkObjs = rel.toString();
  }
  
  /**
   * Handles transfer between values between UI element and 
   * back-end in different circumstances.
   * 
   * @param configuration  build configuration of option 
   *                       (may be IConfiguration or IResourceConfiguration)
   * @param holder         contains the holder of the option
   * @param option         the option that is handled
   * @param extraArgument  extra argument for handler
   * @param event          event to be handled, one of the following: 
   *                       (EVENT_OPEN = 1, EVENT_CLOSE = 2, 
   *                        EVENT_SETDEFAULT = 3, 
   *                        EVENT_APPLY = 4, EVENT_LOAD = 5)
   *
   * @return  True when the event was handled, false otherwise.
   * This enables default event handling can take place.
   */
  public boolean handleValue(IBuildObject configuration, IHoldsOptions holder,
                             IOption option, String extraArgument, int event) {
    if (event == EVENT_CLOSE) return false;
    
    try {
      String mgrId = extraArgument;
      Boolean enabled = (Boolean) option.getValue();
      
      if (enabled==null) {
        enabled = defaultMgrStatusMap.get(mgrId);
        option.setValue(enabled.booleanValue());
      }
      
      updateRelocationLink(mgrId, enabled);      
    } catch (Exception e) {
      return false;
    }
    
    return true;
  }

  /**
   * Checks whether the value of an option is its default value.
   * 
   * @param configuration  build configuration of option 
   *                       (may be IConfiguration or IResourceConfiguration)
   * @param holder         contains the holder of the option
   * @param option         the option that is handled
   * @param extraArgument  extra argument for handler
   *
   * The additional options besides configuration are supplied to  
   * provide enough information for querying the default value from 
   * a potential data storage back-end.
   * 
   * @return  True if the options value is its default value and
   * False otherwise. This enables that default event handling can 
   * take place.
   */
  public boolean isDefaultValue(IBuildObject configuration,
      IHoldsOptions holder, IOption option, String extraArgument) {
    String mgrId = extraArgument;
    return defaultMgrStatusMap.get(mgrId).equals(option.getValue());
  }

  /**
   * Checks whether an enumeration value of an option is currently a 
   * valid choice. The use-case for this method is the case, where
   * the set of valid enumerations in the plugin.xml file changes.
   * The UI will remove entries from selection lists if the value 
   * returns false.
   * 
   * @param configuration  build configuration of option 
   *                       (may be IConfiguration or IResourceConfiguration)
   * @param holder         contains the holder of the option
   * @param option         the option that is handled
   * @param extraArgument  extra argument for handler
   * @param enumValue      enumeration value that is to be checked
   *
   * The additional options besides configuration are supplied to  
   * provide enough information for querying information from a 
   * a potential data storage back-end.
   * 
   * @return  True if the enumeration value is valid and False 
   * otherwise.
   */
  public boolean isEnumValueAppropriate(IBuildObject configuration,
      IHoldsOptions holder, IOption option, String extraArgument,
      String enumValue) {
    // By default return true for all the enum values.
    return true;
  }

}