juce中的CallbackMessage

这个类作为所有消息的基类,主要是包装了回调函数 virtual void messageCallback() = 0;

/*
  ==============================================================================

   This file is part of the JUCE library.
   Copyright (c) 2015 - ROLI Ltd.

   Permission is granted to use this software under the terms of either:
   a) the GPL v2 (or any later version)
   b) the Affero GPL v3

   Details of these licenses can be found at: www.gnu.org/licenses

   JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
   A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

   ------------------------------------------------------------------------------

   To release a closed-source product which uses JUCE, commercial licenses are
   available: visit www.juce.com for more information.

  ==============================================================================
*/

#ifndef JUCE_CALLBACKMESSAGE_H_INCLUDED
#define JUCE_CALLBACKMESSAGE_H_INCLUDED

//==============================================================================
/**
    A message that invokes a callback method when it gets delivered.

    You can use this class to fire off actions that you want to be performed later
    on the message thread.

    To use it, create a subclass of CallbackMessage which implements the messageCallback()
    method, then call post() to dispatch it. The event thread will then invoke your
    messageCallback() method later on, and will automatically delete the message object
    afterwards.

    Always create a new instance of a CallbackMessage on the heap, as it will be
    deleted automatically after the message has been delivered.

    @see MessageManager, MessageListener, ActionListener, ChangeListener
*/
class JUCE_API  CallbackMessage   : public MessageManager::MessageBase
{
public:
    //==============================================================================
    CallbackMessage() noexcept {}

    /** Destructor. */
    ~CallbackMessage() {}

    //==============================================================================
    /** Called when the message is delivered.

        You should implement this method and make it do whatever action you want
        to perform.

        Note that like all other messages, this object will be deleted immediately
        after this method has been invoked.
    */
    virtual void messageCallback() = 0;

private:
    // Avoid the leak-detector because for plugins, the host can unload our DLL with undelivered
    // messages still in the system event queue. These aren‘t harmful, but can cause annoying assertions.
    JUCE_DECLARE_NON_COPYABLE (CallbackMessage)
};

#endif   // JUCE_CALLBACKMESSAGE_H_INCLUDED

  

时间: 2024-10-13 11:21:04

juce中的CallbackMessage的相关文章

juce 中的WeakReference分析

juce中的WeakReference设计得比较巧妙,巧妙就是使用delete之后就可以通知道WeakReference,原理其实也很间单,其实就是在对象里添加了一个子对象masterReference,对象在析构的时候主动调用masterReference.clear();,这样来达到通知弱指针的这个对象已经销毁了,可以设置为空了的目的. 感觉juce最后调用个clear还是觉得有点生硬,外层最好还是再嵌套一层,析构的时候自动调用clear就可以了,对象申明也写成宏,这样的话就简洁多了. 使用

juce中的BailOutChecker

界面库中值得注意的一点就是对象响应事件的时候自身被删除了,那么后续的访问自然就会出问题,所以需要在响应事件之后先添加引用,相关处理之后再查看自身是否已经被删除,如果已经被删除那么就直接退出.juce中通过BailOutChecker来进行这处检查,内部实现很简单也就是通过弱引用来进行,关于弱引用请看上一篇文章 //============================================================================== /** A class t

juce中的引用计数

这个类提供了最基本的引用计数管理,界面库中,经常都需要消息发送,而带来的后果就是不知道消息中包含的对象是否还存在,如果不能很好管理的话就容易出现访问销毁了的对象这样的情况,所以,juce的界面无素也基于引用计数是个不错的选择 #ifndef JUCE_REFERENCECOUNTEDOBJECT_H_INCLUDED #define JUCE_REFERENCECOUNTEDOBJECT_H_INCLUDED //=========================================

juce 中的ReferenceCountedObjectPtr

提供了对引用计数对象的管理,其实也就是操作引用计数对象,当引用计数为零的时候将对象销毁,值得学习的是juce是如果将引用计数对象和它的智能指针结合在一起的,这个后面再加分析 //============================================================================== /** A smart-pointer class which points to a reference-counted object. The template

juce中的内存泄漏检测

非常值得借鉴的做法,基于引用计数和局部静态变量,代码比较简单不加详解. //============================================================================== /** Embedding an instance of this class inside another class can be used as a low-overhead way of detecting leaked instances. This cl

juce中的Singleton

说明上其实很明白,支持多线程,防止重复创建,同时支持如果删除以后就不在创建,利用局部静态变量进行标记.挺通用,看来下次写个c11版本的 //============================================================================== /** Macro to declare member variables and methods for a singleton class. To use this, add the line ju

juce中真正的窗口过程

函数所在的具体位置. LRESULT peerWindowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { //============================================================================== case WM_NCHITTEST: if ((styleFlags & windowIgnoresMouseClicks

一起学JUCE之HashMap

基于哈希表的 Map 接口的实现.此实现提供所有可选的映射操作,并允许使用 null 值和 null 键.(除了非同步和允许使用 null 之外,HashMap 类与 Hashtable 大致相同.)此类不保证映射的顺序,特别是它不保证该顺序恒久不变. 此实现假定哈希函数将元素适当地分布在各桶之间,可为基本操作(get 和 put)提供稳定的性能.迭代 collection 视图所需的时间与 HashMap 实例的“容量”(桶的数量)及其大小(键-值映射关系数)成比例.所以,如果迭代性能很重要,

AJAX技术在PHP开发中的简单应用

AJAX无疑是2005年炒的最热的Web开发技术之一,当然,这个功劳离不开Google.我只是一个普通开发者,使用AJAX的地方不是特别多,我就简单的把我使用的心得说一下.(本文假设用户已经具有JavaScript.HTML.CSS等基本的Web开发能力) [AJAX介绍] Ajax是使用客户端脚本与Web服务器交换数据的Web应用开发方法.Web页面不用打断交互流程进行重新加裁,就可以动态地更新.使用Ajax,用户可以创建接近本地桌面应用的直接.高可用.更丰富.更动态的Web用户界面. 异步J