2025-08-03 10:37:17 -07:00
|
|
|
/* Copyright (C) 2025 Wildfire Games.
|
2023-12-02 16:30:12 -08:00
|
|
|
* This file is part of 0 A.D.
|
2010-01-09 11:20:14 -08:00
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
2010-01-09 11:20:14 -08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
2010-01-09 11:20:14 -08:00
|
|
|
* 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.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2023-12-02 16:30:12 -08:00
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
2010-01-09 11:20:14 -08:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef INCLUDED_MESSAGE
|
|
|
|
|
#define INCLUDED_MESSAGE
|
|
|
|
|
|
2025-08-03 10:37:17 -07:00
|
|
|
#include "lib/code_annotation.h"
|
2010-01-09 11:20:14 -08:00
|
|
|
|
2025-08-07 10:53:23 -07:00
|
|
|
#include <js/RootingAPI.h>
|
|
|
|
|
#include <js/TypeDecls.h>
|
|
|
|
|
#include <js/Value.h>
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
2023-06-21 00:50:00 -07:00
|
|
|
class ScriptRequest;
|
|
|
|
|
|
2010-01-09 11:20:14 -08:00
|
|
|
class CMessage
|
|
|
|
|
{
|
|
|
|
|
NONCOPYABLE(CMessage);
|
|
|
|
|
protected:
|
|
|
|
|
CMessage() { }
|
|
|
|
|
public:
|
2010-03-29 03:22:34 -07:00
|
|
|
virtual ~CMessage() { }
|
2010-07-18 08:19:49 -07:00
|
|
|
virtual int GetType() const = 0;
|
2010-01-09 11:20:14 -08:00
|
|
|
virtual const char* GetScriptHandlerName() const = 0;
|
2010-01-22 12:03:14 -08:00
|
|
|
virtual const char* GetScriptGlobalHandlerName() const = 0;
|
2023-06-21 00:50:00 -07:00
|
|
|
virtual JS::Value ToJSVal(const ScriptRequest&) const = 0;
|
|
|
|
|
JS::Value ToJSValCached(const ScriptRequest&) const;
|
2010-09-17 10:53:26 -07:00
|
|
|
private:
|
2015-01-24 06:46:52 -08:00
|
|
|
mutable std::unique_ptr<JS::PersistentRootedValue> m_Cached;
|
2010-01-09 11:20:14 -08:00
|
|
|
};
|
|
|
|
|
// TODO: GetType could be replaced with a plain member variable to avoid some
|
|
|
|
|
// virtual calls, if that turns out to be worthwhile
|
|
|
|
|
|
2023-06-21 00:50:00 -07:00
|
|
|
CMessage* CMessageFromJSVal(int mtid, const ScriptRequest&, JS::HandleValue);
|
2010-01-09 11:20:14 -08:00
|
|
|
|
|
|
|
|
#endif // INCLUDED_MESSAGE
|