File: PluginIPCUtils.h

package info (click to toggle)
audacity 3.2.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 106,704 kB
  • sloc: cpp: 277,038; ansic: 73,623; lisp: 7,761; python: 3,305; sh: 2,715; perl: 821; xml: 275; makefile: 119
file content (85 lines) | stat: -rw-r--r-- 2,829 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/**********************************************************************

  Audacity: A Digital Audio Editor

  @file PluginIPCUtils.h

  @author Vitaly Sverchinsky

  @brief Provides a set of internal commonly used functions/structures

  Part of lib-module-manager library.

**********************************************************************/

#pragma once

#include <vector>
#include <wx/string.h>
#include "XMLTagHandler.h"

class IPCChannel;
class PluginDescriptor;
class XMLWriter;

namespace detail
{
   ///Helper function that extracts plugin provider id and plugin path from the item string
   ///return true if item string was successfully parsed
   bool ParseRequestString(const wxString& req, wxString& providerId, wxString& pluginPath);

   ///Helper function that builds item string from given plugin provider id and plugin path strings
   ///return Item string that can be passed as argument to wxConnection::Request
   wxString MakeRequestString(const wxString& providerId, const wxString& pluginPath);

   ///Writes the length of the string and string bytes into the channel.
   ///Message can be then extracted with InputMessageReader
   void PutMessage(IPCChannel& channel, const wxString& value);

   ///Stores consumed bytes into buffer,
   ///so that individual messages can be extracted later.
   class InputMessageReader
   {
      std::vector<char> mBuffer;
   public:
      ///fills internal buffer
      void ConsumeBytes(const void* bytes, size_t length);

      ///@returns true if buffer contains at least one complete message
      bool CanPop() const noexcept;
      ///extracts message from the buffer, use CanPop() to check if message
      ///is present first
      wxString Pop();
   };

   ///Host uses this structure to build a response and store it
   ///into xml form before sending to the other side. Main application
   ///uses this structure to restore response from the xml document received
   ///as a message
   class PluginValidationResult final : public XMLTagHandler
   {
      std::vector<PluginDescriptor> mDescriptors;
      wxString mErrorMessage;
      bool mHasError{false};
   public:

      ///Result is valid if error flag was not set and
      ///contains at least one plugin descriptor.
      bool IsValid() const noexcept;

      bool HasError() const noexcept;
      const wxString& GetErrorMessage() const noexcept;

      void Add(PluginDescriptor&& desc);
      void SetError(const wxString& msg);

      const std::vector<PluginDescriptor>& GetDescriptors() const noexcept;

      bool HandleXMLTag(const std::string_view& tag, const AttributesList& attrs) override;
      void HandleXMLEndTag(const std::string_view&) override;
      XMLTagHandler* HandleXMLChild(const std::string_view& tag) override;

      void WriteXML(XMLWriter& writer) const;
   };

}