1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.objectweb.fractal.cecilia.composite.c.components;
25
26 import java.util.List;
27 import java.util.Map;
28
29 import org.objectweb.fractal.adl.ADLException;
30 import org.objectweb.fractal.adl.ComponentVisitor;
31 import org.objectweb.fractal.adl.Node;
32 import org.objectweb.fractal.adl.components.ComponentContainer;
33 import org.objectweb.fractal.api.Component;
34 import org.objectweb.fractal.cecilia.adl.AbstractInstantiationTask;
35 import org.objectweb.fractal.cecilia.adl.SourceCodeProvider;
36 import org.objectweb.fractal.cecilia.adl.file.CodeWriter;
37 import org.objectweb.fractal.task.core.AbstractTaskFactoryUser;
38 import org.objectweb.fractal.task.core.TaskException;
39 import org.objectweb.fractal.task.core.primitive.annotations.ClientInterface;
40 import org.objectweb.fractal.task.core.primitive.annotations.ServerInterface;
41 import org.objectweb.fractal.task.core.primitive.annotations.ServerInterfaces;
42 import org.objectweb.fractal.task.core.primitive.annotations.TaskParameters;
43
44
45
46
47
48 public class ComponentInstantiationVisitor extends AbstractTaskFactoryUser
49 implements
50 ComponentVisitor {
51
52
53
54
55
56
57
58
59
60 public Component visit(final List<Node> path,
61 final ComponentContainer container, final Map<Object, Object> context)
62 throws ADLException, TaskException {
63 return taskFactoryItf.newPrimitiveTask(new ComponentInstantiationTask(),
64 container);
65 }
66
67
68
69
70
71
72
73
74
75 @TaskParameters("componentNode")
76 @ServerInterfaces(@ServerInterface(name = "component-instantiation-provider", signature = SourceCodeProvider.class, record = "role:componentInstantiation, id:%", parameters = "componentNode"))
77 public static class ComponentInstantiationTask
78 extends
79 AbstractInstantiationTask {
80
81
82
83
84
85
86 @ClientInterface(name = "bc-instantiation-provider", record = "role:controllerInstantiation, id:%, controller:BC", parameters = "componentNode")
87 public SourceCodeProvider bcInstantiationProviderItf;
88
89
90 @ClientInterface(name = "cc-instantiation-provider", record = "role:controllerInstantiation, id:%, controller:CC", parameters = "componentNode")
91 public SourceCodeProvider ccInstantiationProviderItf;
92
93
94
95
96 @Override
97 protected String processSourceCode() throws Exception {
98 final CodeWriter cw = new CodeWriter("Composite Instantiation Builder");
99 final String instanceName = instanceNameProviderItf.getCInstanceName();
100
101 cw.appendln("// --------------------------------------------------------"
102 + "---------------------");
103 cw.append("// Declare instance ").append(
104 instanceNameProviderItf.getInstanceName()).endl();
105 cw.append("// from type ").append(
106 typeNameProviderItf.getTypeName()).endl();
107 cw.appendln("// --------------------------------------------------------"
108 + "---------------------");
109
110
111
112
113
114
115 cw.append("extern struct __cecilia_defaultCompositeData_t ").append(
116 instanceName).append(";").endl();
117
118
119
120
121 cw.appendln(ccInstantiationProviderItf.getSourceCode()).endl();
122 cw.appendln(bcInstantiationProviderItf.getSourceCode()).endl();
123
124
125 cw.append("struct __cecilia_defaultCompositeData_t ")
126 .append(instanceName).append(" = {").endl();
127 cw.appendln("// Server interfaces");
128 cw.append("{ &__cecilia_defaultComposite_ComponentMeths, ").endl();
129 cw.append("&").append(instanceName).append("}, // myreference").endl();
130 cw.append("{ &__cecilia_defaultComposite_BindingControllerMeths, ")
131 .endl();
132 cw.append("&").append(instanceName).append("}, // bc").endl();
133 cw.append("{ &__cecilia_defaultComposite_LifeCycleControllerMeths, ")
134 .endl();
135 cw.append("&").append(instanceName).append("}, // lcc").endl();
136 cw.append("{ &__cecilia_defaultComposite_ContentControllerMeths, ")
137 .endl();
138 cw.append("&").append(instanceName).append("}, // cc").endl();
139 cw.appendln("// private data");
140 cw.append("sizeof(").append(instanceName).append(
141 "_subComponents) / sizeof(").append(instanceName).append(
142 "_subComponents[0]), // nbSubComponents").endl();
143 cw.append("sizeof(").append(instanceName).append("_bindings) / sizeof(")
144 .append(instanceName).append("_bindings[0]), // nbBindings").endl();
145 cw.append("0, // started").endl();
146 cw.append(instanceName).append("_subComponents,").endl();
147 cw.append(instanceName).append("_bindings,").endl();
148 cw.appendln("};");
149
150 return cw.toString();
151 }
152 }
153
154 }