public static ResultCode OpenNcaFs(ServiceCtx context, string ncaPath, LibHac.Fs.IStorage ncaStorage, out IFileSystem openedFileSystem)
        {
            openedFileSystem = null;

            try
            {
                Nca nca = new Nca(context.Device.System.KeySet, ncaStorage);

                if (!nca.SectionExists(NcaSectionType.Data))
                {
                    return(ResultCode.PartitionNotFound);
                }

                LibHac.Fs.Fsa.IFileSystem fileSystem = nca.OpenFileSystem(NcaSectionType.Data, context.Device.System.FsIntegrityCheckLevel);
                using var sharedFs = new SharedRef <LibHac.Fs.Fsa.IFileSystem>(fileSystem);

                using SharedRef <LibHac.FsSrv.Sf.IFileSystem> adapter = FileSystemInterfaceAdapter.CreateShared(ref sharedFs.Ref(), true);

                openedFileSystem = new IFileSystem(ref adapter.Ref());
            }
            catch (HorizonResultException ex)
            {
                return((ResultCode)ex.ResultValue.Value);
            }

            return(ResultCode.Success);
        }
Example #2
0
        [CommandHipc(1)] // 6.0.0+
        // Add(object<nn::fssrv::sf::IFileSystem>)
        public ResultCode Add(ServiceCtx context)
        {
            using SharedRef <LibHac.FsSrv.Sf.IFileSystem> fileSystem = GetObject <IFileSystem>(context, 0).GetBaseFileSystem();

            Result result = _baseCommitManager.Get.Add(ref fileSystem.Ref());

            return((ResultCode)result.Value);
        }
Example #3
0
 /// <summary>
 /// Creates an instance of this class that holds the given image.
 /// </summary>
 /// <param name="image">Image argument.
 /// Copies of the given instance are created when the image is used through the respective property of this class.</param>
 public ImageProcessedEventArgs(SharedRef <IRasterImageBase> image)
 {
     if (image == null)
     {
         throw new ArgumentNullException("image");
     }
     this.image = image;
 }
Example #4
0
        // CreateDirectoryService() -> object<nn::bcat::detail::ipc::IDeliveryCacheDirectoryService>
        public ResultCode CreateDirectoryService(ServiceCtx context)
        {
            using var service = new SharedRef <LibHac.Bcat.Impl.Ipc.IDeliveryCacheDirectoryService>();

            Result result = _base.Get.CreateDirectoryService(ref service.Ref());

            if (result.IsSuccess())
            {
                MakeObject(context, new IDeliveryCacheDirectoryService(ref service.Ref()));
            }

            return((ResultCode)result.Value);
        }
Example #5
0
        private void SetupStep(SharedRef <IRasterImageBase> imageIn)
        {
            IRasterImageBase imgIn  = imageIn.Reference;
            IRasterImageBase imgOut = imageOut.Reference;

            if (imgIn.Width != imgOut.Width || imgIn.Height != imgOut.Height)
            {
                imageCleaner.AddReference(imageOut);
                imageCleaner.CleanUpAll();
                IRasterImageBase frame = new TrackerVideoFrame(imgIn.Height, imgIn.Width, new byte[imgIn.Height * imgIn.Width]);
                imageOut = SharedRef.Create(frame);
            }
        }
Example #6
0
        // CreateDeliveryCacheStorageService(pid) -> object<nn::bcat::detail::ipc::IDeliveryCacheStorageService>
        public ResultCode CreateDeliveryCacheStorageService(ServiceCtx context)
        {
            ulong pid = context.RequestData.ReadUInt64();

            using var serv = new SharedRef <LibHac.Bcat.Impl.Ipc.IDeliveryCacheStorageService>();

            Result rc = _base.Get.CreateDeliveryCacheStorageService(ref serv.Ref(), pid);

            if (rc.IsSuccess())
            {
                MakeObject(context, new IDeliveryCacheStorageService(context, ref serv.Ref()));
            }

            return((ResultCode)rc.Value);
        }
Example #7
0
        // CreateDeliveryCacheStorageServiceWithApplicationId(nn::ApplicationId) -> object<nn::bcat::detail::ipc::IDeliveryCacheStorageService>
        public ResultCode CreateDeliveryCacheStorageServiceWithApplicationId(ServiceCtx context)
        {
            ApplicationId applicationId = context.RequestData.ReadStruct <ApplicationId>();

            using var service = new SharedRef <LibHac.Bcat.Impl.Ipc.IDeliveryCacheStorageService>();

            Result rc = _base.Get.CreateDeliveryCacheStorageServiceWithApplicationId(ref service.Ref(), applicationId);

            if (rc.IsSuccess())
            {
                MakeObject(context, new IDeliveryCacheStorageService(context, ref service.Ref()));
            }

            return((ResultCode)rc.Value);
        }
Example #8
0
        public P3CapTracker(EquipmentSettings settings) : base()
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }
            this.settings      = new EquipmentSettings(settings);
            this.pointDetector = null;
            this.pointLabeler  = null;
            this.poseEstimator = null;
            IRasterImageBase frame = new TrackerVideoFrame(1, 1, new byte[1]);

            this.imageOut     = SharedRef.Create(frame);
            this.imageCleaner = new SharedRefCleaner(32);
            this.trackerSync  = new object();
        }
Example #9
0
    public void Run()
    {
        Task t1, t2, t3;

        // create 2 objects
        Console.WriteLine("{0}: starting initial scope", Thread.CurrentThread.ManagedThreadId);
        using (var o1 = SharedRef.Create(new MyDisposable("o1")))
            using (var o2 = SharedRef.Create(new MyDisposable("o2")))
            {
                // and 3 sharedrefs, which will be Disposed in 3 separate threads
                var p1  = SharedRef.Create(o1);
                var p2a = SharedRef.Create(o2);
                var p2b = SharedRef.Create(o2);
                t1 = Task.Run(() =>
                {
                    using (p1)
                    {
                        Console.WriteLine("{0}: in another thread, using o1", Thread.CurrentThread.ManagedThreadId);
                        Thread.Sleep(1000);
                        Console.WriteLine("{0}: in another thread, exiting scope", Thread.CurrentThread.ManagedThreadId);
                    }
                });
                t2 = Task.Run(() =>
                {
                    using (p2a)
                    {
                        Console.WriteLine("{0}: in another thread, using o2", Thread.CurrentThread.ManagedThreadId);
                        Thread.Sleep(1000);
                        Console.WriteLine("{0}: in another thread, exiting scope", Thread.CurrentThread.ManagedThreadId);
                    }
                });
                t3 = Task.Run(() =>
                {
                    using (p2b)
                    {
                        Console.WriteLine("{0}: in another thread, using o2", Thread.CurrentThread.ManagedThreadId);
                        Thread.Sleep(1000);
                        Console.WriteLine("{0}: in another thread, exiting scope", Thread.CurrentThread.ManagedThreadId);
                    }
                });
                Console.WriteLine("{0}: exiting initial scope", Thread.CurrentThread.ManagedThreadId);
            }
        t1.Wait();
        t2.Wait();
        t3.Wait();
    }
Example #10
0
        internal async Task <Server[]> ConnectAsync(bool reconnect, bool resumable)
        {
            if (reconnect)
            {
                _dispatcher?.TearDown();
            }
            var loop  = new SharedRef <bool>(false);
            int loops = 0;

            DiscordDebug.WriteLine("Starting connection appempt...");
            Server[] res = null;
            do
            {
                if (loops >= _maxConnectAttempts)
                {
                    throw new GatewayConnectException("Gateway failed to connect " + _maxConnectAttempts + " times, and the connection attempt was aborted.");
                }
                loop.Value = false;
                await _connectMutex.WaitAsync();

                if (_listener == null)
                {
                    string url = await GetGatewayUrlAsync();

                    DiscordDebug.WriteLine("Opening socket...");
                    var socket = new GatewaySocket(this);
                    socket.Connect(url);
                    if (socket.State == WebSocketState.Open)
                    {
                        DiscordDebug.WriteLine("Socket opened.");
                        res = await HandshakeAsync(reconnect, resumable, socket, loop);
                    }
                    else
                    {
                        DiscordDebug.WriteLine("Socket opening failed, trying again...");
                        loop.Value = true;
                    }
                }
                _connectMutex.Release();
                loops++;
            } while (loop.Value);
            DiscordDebug.WriteLine("Connection attempt done.");
            // ReSharper disable once AssignNullToNotNullAttribute (null value is default to get compiler to shut up - whenever res is null, the loop should continue)
            return(res);
        }
Example #11
0
 public void QueueInput(SharedRef <IRasterImageBase> image)
 {
     if (image == null)
     {
         throw new ArgumentNullException("image");
     }
     if (!Running)
     {
         return;
     }
     lock (inputSync) {
         pendingImages.Enqueue(SharedRef.Copy(image));
         // TODO: get limit efficiently
         int imageLimit = 4;                //GetSettings().GetInteger(TrackerProperty.MaxQueuedImages, 4);
         while (pendingImages.Count > imageLimit && pendingImages.Count >= 0)
         {
             pendingImages.Dequeue().Dispose();
         }
     }
     OnInputAvailable(new EventArgs());
 }
        public static ResultCode OpenNsp(ServiceCtx context, string pfsPath, out IFileSystem openedFileSystem)
        {
            openedFileSystem = null;

            try
            {
                LocalStorage storage = new LocalStorage(pfsPath, FileAccess.Read, FileMode.Open);
                using SharedRef <LibHac.Fs.Fsa.IFileSystem> nsp = new(new PartitionFileSystem(storage));

                ImportTitleKeysFromNsp(nsp.Get, context.Device.System.KeySet);

                using SharedRef <LibHac.FsSrv.Sf.IFileSystem> adapter = FileSystemInterfaceAdapter.CreateShared(ref nsp.Ref(), true);

                openedFileSystem = new IFileSystem(ref adapter.Ref());
            }
            catch (HorizonResultException ex)
            {
                return((ResultCode)ex.ResultValue.Value);
            }

            return(ResultCode.Success);
        }
Example #13
0
        public override bool Step()
        {
            if (!Running)
            {
                return(false);
            }

            SharedRef <IRasterImageBase> image = null;

            lock (inputSync) {
                if (pendingImages.Count > 0)
                {
                    image = pendingImages.Dequeue();
                }
            }
            while (image != null)
            {
                using (image) {
                    bool result = false;
                    if (image.Reference != null)
                    {
                        result = Step(image);
                        return(true);
                    }
                }

                lock (inputSync) {
                    if (pendingImages.Count > 0)
                    {
                        image = pendingImages.Dequeue();
                    }
                    else
                    {
                        image = null;
                    }
                }
            }
            return(false);
        }
Example #14
0
        protected override bool Step(SharedRef <IRasterImageBase> imageIn)
        {
            if (!Running)
            {
                return(false);
            }
            SetupStep(imageIn);
            // keypoint detection
            Point2i[] keypoints;
            int       keypointNo = pointDetector.Detect(imageIn.Reference, imageOut.Reference, out keypoints);

            // keypoint labeling
            int[] labels;
            int   labelNo = pointLabeler.Label(keypoints, keypointNo, imageOut.Reference, out labels);
            // TODO: pose detection
            var position = poseEstimator.Estimate(keypoints, labels, labelNo);

            // spread results
            OnInputProcessed(new ImageProcessedEventArgs(imageOut));
            OnPositionDetected(new PositionDetectedEventArgs(position));
            return(true);
        }
Example #15
0
 public IDirectory(ref SharedRef <LibHac.FsSrv.Sf.IDirectory> directory)
 {
     _baseDirectory = SharedRef <LibHac.FsSrv.Sf.IDirectory> .CreateMove(ref directory);
 }
Example #16
0
 public IDeviceOperator(ref SharedRef <LibHac.FsSrv.Sf.IDeviceOperator> baseOperator)
 {
     _baseOperator = SharedRef <LibHac.FsSrv.Sf.IDeviceOperator> .CreateMove(ref baseOperator);
 }
Example #17
0
        public Result GetServiceObject(ref SharedRef <IDisposable> serviceObject)
        {
            serviceObject.SetByCopy(in _serviceObject);

            return(Result.Success);
        }
Example #18
0
 public LibHacArpServiceObject(ref SharedRef <LibHacIReader> serviceObject)
 {
     _serviceObject = SharedRef <LibHacIReader> .CreateCopy(in serviceObject);
 }
Example #19
0
 /// <summary>
 /// Processes the given image.
 /// </summary>
 /// <returns>Whether the operation was successful.</returns>
 /// <param name="image">Image ready for processing. Disposed after the method returns.</param>
 protected abstract bool Step(SharedRef <IRasterImageBase> image);
Example #20
0
 public T Get(SharedRef <T> objRef)
 {
     return(m_SharedRefs[objRef.Id]);
 }
Example #21
0
 public IStorage(ref SharedRef <LibHac.FsSrv.Sf.IStorage> baseStorage)
 {
     _baseStorage = SharedRef <LibHac.FsSrv.Sf.IStorage> .CreateMove(ref baseStorage);
 }
Example #22
0
 public ISaveDataInfoReader(ref SharedRef <LibHac.FsSrv.Sf.ISaveDataInfoReader> baseReader)
 {
     _baseReader = SharedRef <LibHac.FsSrv.Sf.ISaveDataInfoReader> .CreateMove(ref baseReader);
 }
Example #23
0
 /// <summary>
 /// Create a SharedRef from a previous SharedRef, incrementing the reference count.
 /// </summary>
 /// <param name="o"></param>
 public SharedRef(SharedRef <T> o)
 {
     o._t.Retain();
     _t = o._t;
 }
Example #24
0
        public void LoadKip(string kipPath)
        {
            using var kipFile = new SharedRef <IStorage>(new LocalStorage(kipPath, FileAccess.Read));

            ProgramLoader.LoadKip(KernelContext, new KipExecutable(in kipFile));
        }
Example #25
0
 public IDeliveryCacheStorageService(ServiceCtx context, ref SharedRef <LibHac.Bcat.Impl.Ipc.IDeliveryCacheStorageService> baseService)
 {
     _base = SharedRef <LibHac.Bcat.Impl.Ipc.IDeliveryCacheStorageService> .CreateMove(ref baseService);
 }
Example #26
0
 public void Remove(SharedRef <T> objRef)
 {
     m_SharedRefs.Remove(objRef.Id);
 }
 public Result Create(ref SharedRef <IFileSystem> outEncryptedFileSystem,
                      ref SharedRef <IFileSystem> baseFileSystem, IEncryptedFileSystemCreator.KeyId idIndex,
                      in EncryptionSeed encryptionSeed)
Example #28
0
 public IFileSystem(ref SharedRef <LibHac.FsSrv.Sf.IFileSystem> provider)
 {
     _fileSystem = SharedRef <LibHac.FsSrv.Sf.IFileSystem> .CreateMove(ref provider);
 }
Example #29
0
 public IDeliveryCacheFileService(ref SharedRef <LibHac.Bcat.Impl.Ipc.IDeliveryCacheFileService> baseService)
 {
     _base = SharedRef <LibHac.Bcat.Impl.Ipc.IDeliveryCacheFileService> .CreateMove(ref baseService);
 }
Example #30
0
 public IMultiCommitManager(ref SharedRef <LibHac.FsSrv.Sf.IMultiCommitManager> baseCommitManager)
 {
     _baseCommitManager = SharedRef <LibHac.FsSrv.Sf.IMultiCommitManager> .CreateMove(ref baseCommitManager);
 }