py.rs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* This file is part of DarkFi (https://dark.fi)
  2. *
  3. * Copyright (C) 2020-2024 Dyne.org foundation
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Affero General Public License as
  7. * published by the Free Software Foundation, either version 3 of the
  8. * License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Affero General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. use std::sync::{Arc, Mutex};
  19. use crate::{
  20. error::Result,
  21. plugin::{
  22. Category, Plugin, PluginEvent, PluginInstance, PluginInstancePtr, PluginMetadata, SemVer,
  23. SubCategory,
  24. },
  25. scene::SceneGraphPtr,
  26. };
  27. pub struct PythonPlugin {
  28. scene_graph: SceneGraphPtr,
  29. }
  30. impl PythonPlugin {
  31. pub fn new(scene_graph: SceneGraphPtr, sourcecode: String) -> Self {
  32. Self { scene_graph }
  33. }
  34. }
  35. impl Plugin for PythonPlugin {
  36. fn metadata(&self) -> PluginMetadata {
  37. PluginMetadata {
  38. name: "myplugin".to_string(),
  39. title: "My Plugin - Very Good A++".to_string(),
  40. desc: "This is the best plugin ever made. You should use it.".to_string(),
  41. author: "Tyler Durden".to_string(),
  42. version: SemVer {
  43. major: 0,
  44. minor: 0,
  45. patch: 1,
  46. pre: "alpha".to_string(),
  47. build: "".to_string(),
  48. },
  49. cat: Category::Null,
  50. subcat: SubCategory::Null,
  51. }
  52. }
  53. fn start(&self) -> Result<PluginInstancePtr> {
  54. let mut inst = PythonPluginInstance { scene_graph: self.scene_graph.clone() };
  55. Ok(Arc::new(Mutex::new(Box::new(inst))))
  56. }
  57. }
  58. struct PythonPluginInstance {
  59. scene_graph: SceneGraphPtr,
  60. }
  61. impl PluginInstance for PythonPluginInstance {
  62. fn update(&mut self, event: PluginEvent) -> Result<()> {
  63. Ok(())
  64. }
  65. }