00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 import java.io.*;
00019
00020 import imagerec.corba.CORBA;
00021
00022 import FrameManip.Frame;
00023
00024 import org.omg.CORBA.ORB;
00025 import org.omg.CORBA.Policy;
00026 import org.omg.PortableServer.POA;
00027 import org.omg.PortableServer.POAHelper;
00028 import org.omg.PortableServer.Servant;
00029 import org.omg.PortableServer.ThreadPolicy;
00030 import org.omg.PortableServer.ThreadPolicyValue;
00031
00032 import org.omg.CosNaming.NamingContextExt;
00033 import org.omg.CosNaming.NamingContextExtHelper;
00034 import org.omg.CosNaming.NameComponent;
00035
00036 import omg.org.CosPropertyService.Property;
00037
00038 import imagerec.graph.ImageData;
00039
00040 import imagerec.util.ImageDataManip;
00041
00042 import com.bbn.quo.*;
00043 import com.bbn.quo.corba.*;
00044
00045 import Broker.Manager;
00046 import Broker.NamedValue;
00047 import Broker.TaskFactory;
00048 import Broker.RealTimeTask;
00049
00050 import unix.Process;
00051
00052
00053
00054
00055 public class CORBA_quo
00056 extends CORBA
00057 {
00058
00059
00060
00061 static {
00062 System.loadLibrary("JavaUnixUtils");
00063 }
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 private static String readFileIOR(String ior)
00074 {
00075 String retval = null;
00076
00077 if( ior.startsWith("file://") )
00078 {
00079 try
00080 {
00081 String filename = ior.substring(7);
00082 byte bits[];
00083
00084 bits = new byte[(int)new File(filename).length()];
00085 new FileInputStream(filename).read(bits);
00086 retval = new String(bits);
00087 }
00088 catch(FileNotFoundException e)
00089 {
00090 e.printStackTrace();
00091 }
00092 catch(IOException e)
00093 {
00094 e.printStackTrace();
00095 }
00096 }
00097 else
00098 {
00099 retval = ior;
00100 }
00101 return retval;
00102 }
00103
00104
00105
00106
00107 private static final String MANAGER_IOR =
00108 readFileIOR(System.getProperty("edu.utah.broker.manager",
00109 "file://manager.ior"));
00110
00111
00112
00113
00114 private static final String QUO_KERNEL_IOR =
00115 readFileIOR(System.getProperty("edu.utah.broker.quo-kernel",
00116 "file://quoKernel.ior"));
00117
00118
00119
00120
00121 private static final String TASK_IOR =
00122 readFileIOR(System.getProperty("edu.utah.broker.task"));
00123
00124
00125
00126
00127 private String args[];
00128
00129
00130
00131
00132 private ORB orb;
00133
00134
00135
00136
00137
00138
00139 public CORBA_quo(String args[])
00140 {
00141 super(args);
00142
00143 this.args = args;
00144 this.orb = ORB.init(args, null);
00145 }
00146
00147
00148
00149
00150
00151
00152
00153
00154 protected void runServer(String name, final Servant servant)
00155 throws Exception
00156 {
00157 POA root_poa;
00158
00159
00160 root_poa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
00161 root_poa.the_POAManager().activate();
00162
00163
00164 ThreadPolicy thread =
00165 root_poa.create_thread_policy(ThreadPolicyValue.
00166 SINGLE_THREAD_MODEL);
00167
00168 POA poa = root_poa.create_POA("SingleThread",
00169 root_poa.the_POAManager(),
00170 new Policy[] {
00171 thread
00172 });
00173
00174
00175 poa.activate_object(servant);
00176
00177
00178 NamingContextExt namingContext = namingContext(orb);
00179 namingContext.rebind(namingContext.to_name("real_" + name),
00180 poa.servant_to_reference(servant));
00181
00182 RealTimeTask rtt;
00183 Manager manager;
00184 QuoKernel qk;
00185
00186
00187 qk = QuoKernelHelper.
00188 narrow(this.orb.string_to_object(QUO_KERNEL_IOR));
00189
00190 rtt = Broker.RealTimeTaskHelper.
00191 narrow(this.orb.string_to_object(TASK_IOR));
00192
00193 manager = Broker.ManagerHelper.
00194 narrow(this.orb.string_to_object(MANAGER_IOR));
00195
00196 org.omg.CORBA.Any period_any = orb.create_any();
00197 period_any.insert_string("500ms");
00198
00199 org.omg.CORBA.Any pid_any = orb.create_any();
00200 pid_any.insert_long(Process.getProcessID());
00201
00202 manager.AddTask(rtt, new NamedValue[] {
00203 new NamedValue("period", period_any),
00204 new NamedValue("pid", pid_any),
00205 });
00206
00207 ATRWrapper aw = new ATRWrapper(rtt, 500000, 500000);
00208
00209
00210 aw.initSysconds(qk);
00211 aw.initCallbacks();
00212 aw.linkContract(qk);
00213 aw.linkRemoteObject(FrameManip.ProcessorHelper.
00214 narrow(servant._this_object()));
00215
00216 poa.activate_object(aw);
00217
00218 try
00219 {
00220 ImageData id;
00221
00222 id = ImageDataManip.create((int)0, (long)0);
00223 aw.process(new Frame(id.time,
00224 new Property[0],
00225 id.header,
00226 ImageDataManip.writePPM(id)));
00227 }
00228 catch(Throwable th)
00229 {
00230 System.gc();
00231 System.gc();
00232 }
00233
00234
00235 namingContext.rebind(namingContext.to_name(name),
00236 poa.servant_to_reference(aw));
00237
00238 orb.run();
00239 }
00240 }