Exemple #1
0
        public Runtime(Core core)
        {
            mCore         = core;
            mSyscalls     = new Syscalls();
            mIoctls       = new Ioctls();
            mIoctlInvoker = new IoctlInvoker(mCore, mIoctls);

            mCurrentResourceHandle = 1;
            mStaticResourceCount   = 0;

            PhoneApplicationFrame mainPage = (PhoneApplicationFrame)Application.Current.RootVisual;

            mainPage.MouseLeftButtonDown += MouseLeftButtonDown;
            mainPage.MouseMove           += this.MouseMove;
            mainPage.MouseLeftButtonUp   += MouseLeftButtonUp;

            // clear the list of system property providers
            // We clear it before we initialize all the modules, because
            // different modules might register system property providers.
            SystemPropertyManager.ClearSystemPropertyProviders();

            RegisterCleaner(() =>
            {
                Util.RunActionOnMainThreadSync(() =>
                {
                    mainPage.MouseLeftButtonDown -= MouseLeftButtonDown;
                    mainPage.MouseMove           -= this.MouseMove;
                    mainPage.MouseLeftButtonUp   -= MouseLeftButtonUp;
                });
            });

            InitSyscalls();

            mSyscalls.maGetEvent = delegate(int ptr)
            {
                if (mEvents.Count != 0)
                {
                    lock (mEvents)
                    {
                        Event  evt       = mEvents[0];
                        Memory eventData = evt.GetEventData();
                        mEvents.RemoveAt(0);
                        Memory customEventData = evt.GetCustomEventData();
                        if (customEventData != null)
                        {
                            mCore.GetDataMemory().WriteMemoryAtAddress(mCore.GetCustomEventDataPointer(),
                                                                       customEventData, 0, customEventData.GetSizeInBytes());
                            eventData.WriteInt32(MoSync.Struct.MAEvent.data, mCore.GetCustomEventDataPointer());
                        }
                        mCore.GetDataMemory().WriteMemoryAtAddress(ptr, eventData, 0, eventData.GetSizeInBytes());
                    }
                    return(1);
                }
                else
                {
                    return(0);
                }
            };

            mSyscalls.maWait = delegate(int timeout)
            {
                if (timeout <= 0)
                {
                    timeout = 1 << 15;
                }
                mEventWaiter.WaitOne(timeout);
            };

#if !LIB
            mSyscalls.maIOCtl = delegate(int id, int a, int b, int c)
#else
            mSyscalls.maIOCtl = delegate(int id, int a, int b, int c, int args)
#endif
            {
#if !LIB
                return(mIoctlInvoker.InvokeIoctl(id, a, b, c));
#else
                return(mIoctlInvoker.InvokeIoctl(id, a, b, c, args));
#endif
            };

            mSyscalls.maDestroyObject = delegate(int res)
            {
                mResources[res].SetResourceType(MoSync.Constants.RT_PLACEHOLDER);
                mResources[res].SetInternalObject(null);
            };

            mSyscalls.maLoadResource = delegate(int _handle, int _placeholder, int _flag)
            {
                Resource      res         = mResources[_handle];
                BoundedStream stream      = res.GetFileStream();
                Resource      placeholder = mResources[_placeholder];
                if (stream == null)
                {
                    return(0);
                }
                if (placeholder.GetInternalObject() != null)
                {
                    return(0);
                }

                stream.Seek(0, SeekOrigin.Begin);
                LoadResource(stream, (byte)res.GetResourceType(), (uint)stream.Length, placeholder);

                return(1);
            };

            mSyscalls.maLoadResources = delegate(int _data)
            {
                Resource res  = GetResource(MoSync.Constants.RT_BINARY, _data);
                Stream   data = (Stream)res.GetInternalObject();
                return(LoadResources(data, false)?1:0);
            };

            mSyscalls.maCountResources = delegate()
            {
                return(mStaticResourceCount);
            };
        }
Exemple #2
0
        public Runtime(Core core)
        {
            mCore         = core;
            mSyscalls     = new Syscalls();
            mIoctls       = new Ioctls();
            mIoctlInvoker = new IoctlInvoker(mCore, mIoctls);

            PhoneApplicationFrame mainPage = (PhoneApplicationFrame)Application.Current.RootVisual;

            mainPage.MouseLeftButtonDown += MouseLeftButtonDown;
            mainPage.MouseMove           += this.MouseMove;
            mainPage.MouseLeftButtonUp   += MouseLeftButtonUp;

            RegisterCleaner(() =>
            {
                Util.RunActionOnMainThreadSync(() =>
                {
                    mainPage.MouseLeftButtonDown -= MouseLeftButtonDown;
                    mainPage.MouseMove           -= this.MouseMove;
                    mainPage.MouseLeftButtonUp   -= MouseLeftButtonUp;
                });
            });

            InitSyscalls();

            mSyscalls.maGetEvent = delegate(int ptr)
            {
                if (mEvents.Count != 0)
                {
                    lock (mEvents)
                    {
                        Event  evt       = mEvents[0];
                        Memory eventData = evt.GetEventData();
                        mEvents.RemoveAt(0);
                        Memory customEventData = evt.GetCustomEventData();
                        if (customEventData != null)
                        {
                            mCore.GetDataMemory().WriteMemoryAtAddress(mCore.GetCustomEventDataPointer(),
                                                                       customEventData, 0, customEventData.GetSizeInBytes());
                            eventData.WriteInt32(MoSync.Struct.MAEvent.data, mCore.GetCustomEventDataPointer());
                        }
                        mCore.GetDataMemory().WriteMemoryAtAddress(ptr, eventData, 0, eventData.GetSizeInBytes());
                    }
                    return(1);
                }
                else
                {
                    return(0);
                }
            };

            mSyscalls.maWait = delegate(int timeout)
            {
                if (timeout <= 0)
                {
                    timeout = 1 << 15;
                }
                mEventWaiter.WaitOne(timeout);
            };

            mSyscalls.maIOCtl = delegate(int id, int a, int b, int c)
            {
                return(mIoctlInvoker.InvokeIoctl(id, a, b, c));
            };

            mSyscalls.maDestroyObject = delegate(int res)
            {
                mResources[res].SetResourceType(MoSync.Constants.RT_PLACEHOLDER);
                mResources[res].SetInternalObject(null);
            };
        }