Example #1
0
        /// <summary>
        /// Stop logging, in response to "Suspend" power mode event.
        /// </summary>
        /// <remarks>
        /// For use by SsmLogger and test code only.
        /// </remarks>
        internal void Suspend()
        {
            Trace.WriteLine("### PowerModeChanged: Suspend");
            this.TryStateTransition(State.Closing);
            SsmBasicLogger localLogger = this.logger;

            if (localLogger != null)
            {
                Trace.WriteLine("SsmLogger.SystemEvents_PowerModeChanged: stopping logger");
                localLogger.BeginStopLogging(Logger_LoggingStoppedForSuspend, null);
            }
        }
Example #2
0
        /// <summary>
        /// Stops logging
        /// </summary>
        public IAsyncResult BeginStopLogging(AsyncCallback callback, object asyncState)
        {
            Trace.WriteLine("SsmLogger.BeginStopLogging");
            this.TryStateTransition(State.Closing);

            StopLoggingAsyncResult asyncResult = new StopLoggingAsyncResult(callback, asyncState);
            SsmBasicLogger         localLogger = this.logger;

            if (localLogger != null)
            {
                Trace.WriteLine("SsmLogger.BeginStopLogging: stopping logger");
                return(localLogger.BeginStopLogging(Logger_LoggingStopped, asyncResult));
            }
            else
            {
                Trace.WriteLine("SsmLogger.BeginStopLogging: logger gone, returning trivial AsyncResult");
                AsyncResult result = new AsyncResult(callback, asyncState);
                result.Completed();
                //ThreadPool.QueueUserWorkItem(new WaitCallback(delegate { result.Completed(); }));
                return(result);
            }
        }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        private void ReopenStream()
        {
            if ((this.logger != null) && this.logger.IsLogging)
            {
                Trace.WriteLine("SsmLogger.TimerCallback: logger is already running.");
                return;
            }

            Trace.WriteLine("SsmLogger.TimerCallback: Attempting restart.");
            Stream stream = this.GetDataStream(false);

            if (stream == null)
            {
                Trace.WriteLine("SsmLogger.ReopenStream: Unable to open stream, will try again in one second.");

                if (!this.TryStateTransition(State.Resyncing))
                {
                    Trace.WriteLine("SsmLogger.ReopenStream: Going to reset the timer anyway...");
                }

                this.ScheduleRestart(TimeSpan.FromSeconds(1));
                return;
            }

            Trace.WriteLine("SsmLogger.ReopenStream: Stream opened.");
            this.logger.SetEcuStream(stream);
            this.StartLogging();

            if (!this.TryStateTransition(State.Ready))
            {
                Trace.WriteLine("SsmLogger.ReopenStream: Transition to Ready was illegal, stopping.");
                SsmBasicLogger localLogger = this.logger;
                if (localLogger != null)
                {
                    localLogger.BeginStopLogging(Logger_LoggingStopped, null);
                }
            }
        }