| 1 |
/* |
| 2 |
* Copyright (C) 2025 Linux Studio Plugins Project <https://lsp-plug.in/> |
| 3 |
* (C) 2025 Vladimir Sadovnikov <[email protected]> |
| 4 |
* |
| 5 |
* This file is part of lsp-runtime-lib |
| 6 |
* Created on: 29 авг. 2019 г. |
| 7 |
* |
| 8 |
* lsp-runtime-lib is free software: you can redistribute it and/or modify |
| 9 |
* it under the terms of the GNU Lesser General Public License as published by |
| 10 |
* the Free Software Foundation, either version 3 of the License, or |
| 11 |
* any later version. |
| 12 |
* |
| 13 |
* lsp-runtime-lib is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
* GNU Lesser General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU Lesser General Public License |
| 19 |
* along with lsp-runtime-lib. If not, see <https://www.gnu.org/licenses/>. |
| 20 |
*/ |
| 21 |
|
| 22 |
#ifndef LSP_PLUG_IN_FMT_JAVA_HANDLES_H_ |
| 23 |
#define LSP_PLUG_IN_FMT_JAVA_HANDLES_H_ |
| 24 |
|
| 25 |
#include <lsp-plug.in/runtime/version.h> |
| 26 |
#include <lsp-plug.in/common/types.h> |
| 27 |
#include <lsp-plug.in/common/status.h> |
| 28 |
#include <lsp-plug.in/fmt/java/Object.h> |
| 29 |
|
| 30 |
namespace lsp |
| 31 |
{ |
| 32 |
namespace java |
| 33 |
{ |
| 34 |
/** |
| 35 |
* This is implementation of storage for handles read from |
| 36 |
* the object stream |
| 37 |
*/ |
| 38 |
class Handles |
| 39 |
{ |
| 40 |
protected: |
| 41 |
size_t nCapacity; |
| 42 |
Object **vItems; |
| 43 |
size_t nHandle; |
| 44 |
|
| 45 |
public: |
| 46 |
explicit Handles(); |
| 47 |
Handles(const Handles &) = delete; |
| 48 |
Handles(Handles &&) = delete; |
| 49 |
~Handles(); |
| 50 |
|
| 51 |
Handles & operator = (const Handles &) = delete; |
| 52 |
Handles & operator = (Handles &&) = delete; |
| 53 |
|
| 54 |
public: |
| 55 |
/** |
| 56 |
* Allocate new handle identifier |
| 57 |
* @return handle identifier |
| 58 |
*/ |
| 59 |
inline size_t new_handle() { return nHandle++; } |
| 60 |
|
| 61 |
/** |
| 62 |
* Return number of handles |
| 63 |
* @return number of handles |
| 64 |
*/ |
| 65 |
inline size_t handles() const { return nHandle; } |
| 66 |
|
| 67 |
/** |
| 68 |
* Resolve the java object |
| 69 |
* @param handle java object handle |
| 70 |
* @return resolved java object or NULL if not exist |
| 71 |
*/ |
| 72 |
Object *get(size_t handle); |
| 73 |
|
| 74 |
/** |
| 75 |
* Bind object to the specified handle |
| 76 |
* @param obj java object |
| 77 |
* @return status of operation |
| 78 |
*/ |
| 79 |
status_t assign(Object *obj); |
| 80 |
|
| 81 |
/** |
| 82 |
* Clear handle registry and free handle table |
| 83 |
*/ |
| 84 |
void clear(); |
| 85 |
|
| 86 |
/** |
| 87 |
* Flush handle registry and free handle table |
| 88 |
*/ |
| 89 |
void flush(); |
| 90 |
}; |
| 91 |
|
| 92 |
} /* namespace java */ |
| 93 |
} /* namespace lsp */ |
| 94 |
|
| 95 |
#endif /* LSP_PLUG_IN_FMT_JAVA_OBJECTRESOLVER_H_ */ |