LCOV - code coverage report
Current view: top level - muse/framework/rcommand/internal - commanddispatcher.h Coverage Total Hit
Test: filtered_coverage.info Lines: 100.0 % 1 1
Test Date: 2026-11-19 04:14:36

            Line data    Source code
       1              : /*
       2              :  * SPDX-License-Identifier: GPL-3.0-only
       3              :  * MuseScore/Audacity CLA applies
       4              :  *
       5              :  * Copyright (C) 2026 MuseScore/Audacity and others
       6              :  *
       7              :  * This program is free software: you can redistribute it and/or modify
       8              :  * it under the terms of the GNU General Public License version 3 as
       9              :  * published by the Free Software Foundation.
      10              :  *
      11              :  * This program is distributed in the hope that it will be useful,
      12              :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14              :  * GNU General Public License for more details.
      15              :  *
      16              :  * You should have received a copy of the GNU General Public License
      17              :  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
      18              :  */
      19              : #pragma once
      20              : 
      21              : #include "../icommanddispatcher.h"
      22              : 
      23              : #include "global/modularity/ioc.h"
      24              : #include "../icommandsregister.h"
      25              : 
      26              : namespace muse::rcommand {
      27              : class CommandDispatcher : public ICommandDispatcher
      28              : {
      29              :     GlobalInject<ICommandsRegister> commandsRegister;
      30              : 
      31              : public:
      32           32 :     CommandDispatcher() = default;
      33              :     ~CommandDispatcher() override;
      34              : 
      35              :     async::Promise<Response> dispatch(const Request& request, bool maybeRedirect = true) override;
      36              :     void onRequest(Commandable* client, const Command& command, const CallBack& callback) override;
      37              :     void onRequest(Commandable* client, const Command& command, const AsyncCallBack& callback) override;
      38              :     void unreg(Commandable* client) override;
      39              : 
      40              :     async::Channel<Command, bool* /*allow dispatch*/> preDispatch() const override;
      41              :     async::Channel<Command> postDispatch() const override;
      42              :     async::Channel<Command> notRegistered() const override;
      43              : 
      44              :     // for utests
      45              :     Response dispatch(const Command& command, const Params& params = {});
      46              :     Response dispatch(const CommandQuery& query);
      47              : 
      48              : private:
      49              : 
      50              :     struct Client
      51              :     {
      52              :         Commandable* client = nullptr;
      53              :         CallBack callback = nullptr;
      54              :         AsyncCallBack asyncCallback = nullptr;
      55              :     };
      56              : 
      57              :     void reg(Commandable* client, const Command& command, const Client& c);
      58              : 
      59              :     std::map<Command, Client> m_clients;
      60              :     async::Channel<Command, bool* /*allow dispatch*/> m_preDispatch;
      61              :     async::Channel<Command> m_postDispatch;
      62              :     async::Channel<Command> m_notRegistered;
      63              : };
      64              : }
        

Generated by: LCOV version 2.0-1