Exemplo n.º 1
0
        public override void Run(string[] args)
        {
            // Log any unhandled exception.
            AppDomain.CurrentDomain.UnhandledException += (s, e) =>
            {
                var exception = e.ExceptionObject as Exception;
                InternalLog.Error(LogTag, $"Unhandled exception: {exception}");
            };

            // Parse engine arguments passed from the tool. This should be reworked.
            for (int i = args.Length - 1; i >= 0; i--)
            {
                var arg = args[i].Trim('\'');
                if (arg.StartsWith("FLUTTER_ENGINE_ARGS"))
                {
                    var engineArgs = arg.Substring(arg.IndexOf(' '));
                    InternalLog.Debug(LogTag, "Running with: " + engineArgs);

                    // A regex is used here to correctly parse "quoted" strings.
                    // TODO: Avoid using Linq to reduce the memory pressure.
                    EngineArgs.AddRange(Regex.Matches(engineArgs, @"[\""].+?[\""]|[^ ]+")
                                        .Cast <Match>()
                                        .Select(x => x.Value.Trim('"')));
                    break;
                }
            }

            base.Run(args);
        }
Exemplo n.º 2
0
 public static void Debug(
     string message,
     [CallerFilePath] string file   = "",
     [CallerMemberName] string func = "",
     [CallerLineNumber] int line    = 0)
 {
     InternalLog.Debug(LogTag, message, file, func, line);
 }
        public override void OnShutdown()
        {
            InternalLog.Debug("[NetModule ShutDown] channel count is " + m_Channels.Count);
            foreach (var channel in m_Channels)
            {
                channel.Close();
            }

            m_Channels.Clear();
            base.OnShutdown();
        }
 private void OnError(string errorMessage, SocketError?socketError)
 {
     InternalLog.Debug("[TcpChannel OnError] Start.");
     try
     {
         Handler.OnError(errorMessage, socketError == null ? null : (object)socketError.Value);
     }
     catch
     {
         // ignored
     }
     finally
     {
         InternalLog.Debug("[TcpChannel OnError] End.");
     }
 }
        public void Close()
        {
            lock (m_StateLock)
            {
                InternalLog.Debug("[TcpChannel OnClose] Start.");
                if (m_State == NetChannelState.Unknown || m_State == NetChannelState.Closed ||
                    m_State == NetChannelState.Closing ||
                    m_State == NetChannelState.Disconnected)
                {
                    return;
                }

                m_State = NetChannelState.Closing;
            }

            Clear();
            Interlocked.Exchange(ref m_IsSending, 0);

            m_SendingEventArgs.Completed    -= OnSendCompleted;
            m_ReceiveEventArgs.Completed    -= OnReceiveCompleted;
            m_ConnectionEventArgs.Completed -= OnConnectionComplete;
            m_ReceiveStream.Dispose();
            m_SendingStream.Dispose();

            InternalLog.Debug("[TcpChannel OnClose] Before socket shutdown and close.");
            try
            {
                m_Socket.Shutdown(SocketShutdown.Both);
                m_Socket.Close();
            }
            catch
            {
                // ignored
            }
            finally
            {
                InternalLog.Debug("[TcpChannel OnClose] finally block.");
                m_Socket = null;

                lock (m_StateLock)
                {
                    m_State = NetChannelState.Closed;
                }

                InternalLog.Debug("[TcpChannel OnClose] End.");
            }
        }
Exemplo n.º 6
0
        protected override void OnCreate()
        {
            base.OnCreate();

            // Read the current platform version and choose a Tizen 4.0 embedder if applicable.
            Information.TryGetValue("http://tizen.org/feature/platform.version", out PlatformVersion);

            // Read engine arguments passed from the tool.
            ParseEngineArgs();
            InternalLog.Info(LogTag, $"switches: {string.Join(" ", EngineArgs)}");

            // Get the screen size of the currently running device.
            if (!Information.TryGetValue("http://tizen.org/feature/screen.width", out int width) ||
                !Information.TryGetValue("http://tizen.org/feature/screen.height", out int height))
            {
                InternalLog.Error(LogTag, "Could not obtain the screen size.");
                return;
            }
            var windowProperties = new FlutterWindowProperties
            {
                width  = width,
                height = height
            };

            // Get paths to resources required for launch.
            string resPath     = Current.DirectoryInfo.Resource;
            string assetsPath  = $"{resPath}/flutter_assets";
            string icuDataPath = $"{resPath}/icudtl.dat";
            string arch        = RuntimeInformation.ProcessArchitecture switch
            {
                Architecture.X86 => "x86",
                Architecture.X64 => "x64",
                Architecture.Arm => "arm",
                Architecture.Arm64 => "aarch64",
                _ => "",
            };
            string aotLibPath = $"{resPath}/../lib/{arch}/libapp.so";

            using var switches = new StringArray(EngineArgs);
            var engineProperties = new FlutterEngineProperties
            {
                assets_path      = assetsPath,
                icu_data_path    = icuDataPath,
                aot_library_path = aotLibPath,
                switches         = switches.Handle,
                switches_count   = (uint)switches.Length,
            };

            // This check is not actually required, but we want to make sure that libflutter_engine.so is loaded
            // before a call to FlutterCreateWindow() is made to avoid library loading issues on TV emulator.
            if (FlutterEngineRunsAOTCompiledDartCode())
            {
                InternalLog.Debug(LogTag, "Running in AOT mode.");
            }

            Handle = FlutterCreateWindow(ref windowProperties, ref engineProperties);
            if (Handle.IsInvalid)
            {
                throw new Exception("Could not launch a Flutter application.");
            }
        }
        public void ToBinary(BinaryWriter bw, AssetIndexBase obj)
        {
#if PROFILING
            Profiler.BeginSample();
#endif
            var stringMap = new StringMap();
            var resourceGroupInfoSerializer = new ResourceGroupInfoSerializerV2(stringMap);
            var resourceBasicInfoSerializer = new ResourceBasicInfoSerializerV2(stringMap);
            var assetInfoSerializer         = new AssetInfoSerializerV2(stringMap);
            var resourceInfoSerializer      = new ResourceInfoSerializerV2(stringMap);

            bw.Write(obj.Header);
            bw.Write(Version);

            obj.SerializeAugmentedData(bw);

            foreach (var kv in obj.ResourceBasicInfos)
            {
                stringMap.TryAddString(kv.Key, out _);
            }

            // AssetInfos doesn't necessarily contain information about all the assets. So their dependency paths have to
            // be added into stringMap.
            foreach (var kv in obj.AssetInfos)
            {
                stringMap.TryAddString(kv.Key, out _);
                foreach (var dependencyAssetPath in kv.Value.DependencyAssetPaths)
                {
                    stringMap.TryAddString(dependencyAssetPath, out _);
                }
            }

            stringMap.ToBinary(bw);

            bw.Write(obj.ResourceGroupInfos.Count);
            foreach (var resourceGroupInfo in obj.ResourceGroupInfos)
            {
                resourceGroupInfoSerializer.ToBinary(bw, resourceGroupInfo);
            }

            bw.Write(obj.ResourceBasicInfos.Count);
            foreach (var kv in obj.ResourceBasicInfos)
            {
                resourceBasicInfoSerializer.ToBinary(bw, kv.Value);
            }

            bw.Write(obj.AssetInfos.Count);
            foreach (var kv in obj.AssetInfos)
            {
                assetInfoSerializer.ToBinary(bw, kv.Value);
            }

            bw.Write(obj.ResourceInfos.Count);
            foreach (var kv in obj.ResourceInfos)
            {
                resourceInfoSerializer.ToBinary(bw, kv.Value);
            }
#if PROFILING
            InternalLog.Debug($"[AssetIndexSerializerV2 ToBinary] Serialization of asset index takes {Profiler.EndSample().TotalMilliseconds} ms.");
#endif
        }
 private void Receive()
 {
     InternalLog.Debug("[TcpChannel Receive]");
     m_Socket.ReceiveAsync(m_ReceiveEventArgs);
 }