data_compiler.vala 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright (c) 2012-2024 Daniele Bartolini et al.
  3. * SPDX-License-Identifier: GPL-3.0-or-later
  4. */
  5. namespace Crown
  6. {
  7. public class DataCompiler
  8. {
  9. private RuntimeInstance _runtime;
  10. private Guid _id;
  11. private bool _success;
  12. private SourceFunc _compile_callback;
  13. private SourceFunc _refresh_list_callback;
  14. private Gee.ArrayList<Value?> _refresh_list;
  15. public uint _revision;
  16. public DataCompiler(RuntimeInstance runtime)
  17. {
  18. _runtime = runtime;
  19. _id = GUID_ZERO;
  20. _success = false;
  21. _revision = 0;
  22. _compile_callback = null;
  23. _refresh_list_callback = null;
  24. _refresh_list = null;
  25. }
  26. // Returns true if success, false otherwise.
  27. public async bool compile(string data_dir, string platform)
  28. {
  29. if (_compile_callback != null)
  30. return false;
  31. _id = Guid.new_guid();
  32. _success = false;
  33. _runtime.send(DataCompilerApi.compile(_id, data_dir, platform));
  34. _compile_callback = compile.callback;
  35. yield;
  36. return _success;
  37. }
  38. public void compile_finished(bool success, uint revision)
  39. {
  40. _success = success;
  41. _revision = revision;
  42. if (_compile_callback != null)
  43. _compile_callback();
  44. _compile_callback = null;
  45. }
  46. /// Returns the list of resources that have changed since @a since_revision.
  47. public async Gee.ArrayList<Value?> refresh_list(uint since_revision)
  48. {
  49. if (_refresh_list_callback != null)
  50. return new Gee.ArrayList<Value?>();
  51. _runtime.send(DataCompilerApi.refresh_list(since_revision));
  52. _refresh_list_callback = refresh_list.callback;
  53. yield;
  54. return _refresh_list;
  55. }
  56. public void refresh_list_finished(Gee.ArrayList<Value?> resources)
  57. {
  58. unowned GLib.SourceFunc callback = _refresh_list_callback;
  59. _refresh_list_callback = null;
  60. _refresh_list = resources;
  61. if (callback != null)
  62. callback();
  63. }
  64. }
  65. } /* namespace Crown */