/* Nicolò: * used to start the automatic setup (by DLL) */ public static void StartSetup(GuiSetupCallback configurationListenedDelegate, GuiErrorCallback errorHandlingDelegate) { //----- check for existing auto-setup ----- if (status == Lead.setting_up) { Console.WriteLine("Auto-setup already running: request ignored"); return; } //----- set the DLL callback ----- // autopresentation handling //dllSetupCallback = (string list_boards) => DllSetupPublish(list_boards); // error handling //dllErrorCallback = (string type, string message) => DllErrorPublish(type, message); Synchronizer.error_handling(dllErrorCallback); //set in the C++ //----- set the GUI callback ----- // autopresentation handling Synchronizer.guiSetupCallback = configurationListenedDelegate; // error handling Synchronizer.guiErrorCallback = errorHandlingDelegate; Configuration fake_conf = new Configuration("Auto-setup"); Log.InsertLog(fake_conf, Log.MessageType.configuration_update, "Changed the delegate that handles the errors"); //----- update the target and status ----- targetConfiguration = fake_conf; status = Lead.setting_up; //----- activate WiFi access point ----- hotspot.start(); //----- actually start the C++ automatic setup ----- start_setup(dllSetupCallback, dllErrorCallback); }
// ~-----methods------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ /* Nicolò: * used to start the computation of the C++ software module (by DLL) */ public static void StartEngine(Configuration configuration, GuiErrorCallback errorHandlingDelegate) { // local variables string boardsInfo = ""; // check number of boards if (configuration.BoardCount() < 2) { throw new Exception("Impossible to start a configuration having less than 2 listening boards"); } // check for existing and running configuration if (targetConfiguration == null) { targetConfiguration = new Configuration(""); } if (status == Lead.running) { if (targetConfiguration.ConfigurationID.Equals("")) { throw new Exception("The previous target configuration was cleared, but its status is still '" + status.ToString() + "'"); } else { throw new Exception("Requested '" + configuration.ConfigurationID + "' configuration, but the '" + targetConfiguration.ConfigurationID + "' one was already running"); } } // set the target configuration and its status targetConfiguration = configuration; status = Lead.setting_up; // concatenate board information foreach (Board b in configuration.Boards) { boardsInfo += b.BoardID + "|" + b.X + "|" + b.Y + "_"; } boardsInfo = boardsInfo.Substring(0, boardsInfo.Length - 1); // set the DLL callback //dllErrorCallback = (string type, string message) => DllErrorPublish(type, message); Synchronizer.error_handling(dllErrorCallback); //set in the C++ Synchronizer.guiErrorCallback = errorHandlingDelegate; Log.InsertLog(configuration, Log.MessageType.configuration_update, "Changed the delegate that handles the errors"); // clear the previously occurred errors message = ""; errorType = Reason.NoError; // activate WiFi access point hotspot.start(); // actually start the C++ Collector engine try { start_engine(configuration.ConfigurationID, configuration.BoardCount(), boardsInfo, dllErrorCallback); } catch (Exception e) { Synchronizer.errorType = Reason.BadConfiguration; Synchronizer.message = e.Message; StopEngine(targetConfiguration); throw; // re-throw the same exception } // update the targetConfiguration status status = Lead.running; // notify the starting of the engine, by inserting in the 'log' table Log.InsertLog(configuration, Log.MessageType.engine_start, "Started the configuration '" + configuration.ConfigurationID + "'"); }