using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Collections; using System.Net.Sockets; namespace CPlus_GW { public class CPlusGW { public string gatewayID; public bool status = false; public static InterthreadMessageQueue locationQueue = new InterthreadMessageQueue(); public static InterthreadMessageQueue DBQueueLocation = new InterthreadMessageQueue(); public static InterthreadMessageQueue DBQueueRFID = new InterthreadMessageQueue(); public static InterthreadMessageQueue sendSMSQueue = new InterthreadMessageQueue(); public static ArrayList waitConfSMSList = new ArrayList(); public static InterthreadMessageQueue confSMSQueue = new InterthreadMessageQueue(); //queue for GUI display public static InterthreadMessageQueue TextQueue = new InterthreadMessageQueue(); public static UdpClient smsUDPclient = null; LocationThread LocationConnection = null; // the threads for the 5 services we handle(ARS/watcher thread is started in StartARSService) //DBconnThread DBConnection = null; ReceiveSMSThread ReceiveSMSthr = null; SendSMSThread SendSMSthr = null; Thread LocationThreadobj = null; Thread ReceiveSMSThreadobj = null; Thread SendSMSThreadobj = null; WatcherServerThread server; public CPlusGW() { if (Program.cfg.errorMSG != "") { Console.WriteLine("Error reading config file.\n\rPlease press any key to exit!!!"); TextQueue.PostItem("Error reading config file.Please check \"GWconfig.ini\""); //Console.ReadKey(); return; } } public void Start() { //MotoTRBOGW p = new MotoTRBOGW(); try { if(smsUDPclient ==null) smsUDPclient = new UdpClient(Program.cfg.smsPort_r); StartARSService(); StartLocationService(); StartSMSService(); } catch (Exception ex) { SafeMobileLib.Utils.WriteLine("CPlusGW Start Exception: " + ex.ToString(), ConsoleColor.Red); } status = true; //p.StartOC4JService(); } public void Stop() { //smsUDPclient.Close(); server.Stop(); status = false; } void StartARSService() { SafeMobileLib.Utils.WriteLine("Starting Location Service", ConsoleColor.DarkMagenta); server = new WatcherServerThread(Program.cfg.ctrlIP, Program.cfg.arsPort, gatewayID, Program.cfg.report); server.Start(); //server.SubscribeALL(cfg.dialogid); server.SubscribeALL(1234); } public void StartLocationService() { SafeMobileLib.Utils.WriteLine("Starting Location Service", ConsoleColor.DarkMagenta); // create thread to listen UDP LocationConnection = new LocationThread(); LocationConnection.port = Program.cfg.locPort_r; //LocationConnection.parent = this; LocationThreadobj = new Thread(new ThreadStart(LocationConnection.HandleConnection)); LocationThreadobj.IsBackground = true; LocationThreadobj.Start(); } public void StartSMSService() { SafeMobileLib.Utils.WriteLine("Starting SMS Service", ConsoleColor.DarkMagenta); // create thread to listen UDP ReceiveSMSthr = new ReceiveSMSThread((ushort)Program.cfg.smsPort_r, gatewayID); //ARSConnection.parent = this; ReceiveSMSThreadobj = new Thread(new ThreadStart(ReceiveSMSthr.HandleConnection)); ReceiveSMSThreadobj.IsBackground = true; ReceiveSMSThreadobj.Start(); // create thread to listen UDP SendSMSthr = new SendSMSThread(Program.cfg.smsPort); //ARSConnection.parent = this; SendSMSThreadobj = new Thread(new ThreadStart(SendSMSthr.HandleConnection)); SendSMSThreadobj.IsBackground = true; SendSMSThreadobj.Start(); } } }