C++11 library providing functionality common to all adapters.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

145 lines
4.2 KiB

  1. // This file is under GNU General Public License 3.0
  2. // see LICENSE.txt
  3. //#include <pEp/group.h>
  4. // clang-format off
  5. #include "group_manager_api.h"
  6. #include "grp_driver_replicator.hh"
  7. #include "pEpLog.hh"
  8. #include "grp_driver_dummy.hh"
  9. #include "grp_driver_engine.hh"
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. using namespace std;
  14. using namespace pEp;
  15. Adapter::GroupDriverReplicator adapter_grp_manager{};
  16. shared_ptr<Adapter::GroupDriverDummy> grp_drv_dummy;
  17. shared_ptr<Adapter::GroupDriverEngine> grp_drv_engine;
  18. DYNAMIC_API PEP_STATUS adapter_group_init()
  19. {
  20. PEP_STATUS status = PEP_STATUS_OK;
  21. try {
  22. const string lm_dummy_db_filename = "groups.db";
  23. #ifdef WIN32
  24. const string lm_dummy_db_path = string(::per_user_directory()) + "\\" + lm_dummy_db_filename;
  25. #else
  26. const string lm_dummy_db_path = string(::per_user_directory()) + "/" + lm_dummy_db_filename;
  27. #endif
  28. if(!grp_drv_dummy) {
  29. grp_drv_dummy = make_shared<Adapter::GroupDriverDummy>(lm_dummy_db_path);
  30. }
  31. if(!grp_drv_engine) {
  32. grp_drv_engine = make_shared<Adapter::GroupDriverEngine>();
  33. }
  34. adapter_grp_manager.set_replication_source(*grp_drv_dummy.get());
  35. adapter_grp_manager.set_replication_destination(*grp_drv_engine.get());
  36. } catch (const std::exception &e) {
  37. pEpLog(Utils::nested_exception_to_string(e));
  38. status = PEP_UNKNOWN_ERROR;
  39. } catch (...) {
  40. pEpLog("unknown exception");
  41. status = PEP_UNKNOWN_ERROR;
  42. }
  43. return status;
  44. }
  45. /*************************************************************************************************
  46. * Group management functions
  47. *************************************************************************************************/
  48. DYNAMIC_API PEP_STATUS adapter_group_create(
  49. PEP_SESSION session,
  50. pEp_identity *group_identity,
  51. pEp_identity *manager,
  52. identity_list *memberlist)
  53. {
  54. pEpLog("called");
  55. PEP_STATUS status = adapter_grp_manager.adapter_group_create(
  56. session,
  57. group_identity,
  58. manager,
  59. memberlist);
  60. return status;
  61. }
  62. DYNAMIC_API PEP_STATUS adapter_group_dissolve(
  63. PEP_SESSION session,
  64. pEp_identity *group_identity,
  65. pEp_identity *manager)
  66. {
  67. pEpLog("called");
  68. PEP_STATUS status = adapter_grp_manager.adapter_group_dissolve(session, group_identity, manager);
  69. return status;
  70. }
  71. DYNAMIC_API PEP_STATUS adapter_group_invite_member(
  72. PEP_SESSION session,
  73. pEp_identity *group_identity,
  74. pEp_identity *group_member)
  75. {
  76. pEpLog("called");
  77. PEP_STATUS status = adapter_grp_manager.adapter_group_invite_member(
  78. session,
  79. group_identity,
  80. group_member);
  81. return status;
  82. }
  83. DYNAMIC_API PEP_STATUS adapter_group_remove_member(
  84. PEP_SESSION session,
  85. pEp_identity *group_identity,
  86. pEp_identity *group_member)
  87. {
  88. pEpLog("called");
  89. PEP_STATUS status = adapter_grp_manager.adapter_group_remove_member(
  90. session,
  91. group_identity,
  92. group_member);
  93. return status;
  94. }
  95. DYNAMIC_API PEP_STATUS adapter_group_join(
  96. PEP_SESSION session,
  97. pEp_identity *group_identity,
  98. pEp_identity *as_member)
  99. {
  100. pEpLog("called");
  101. PEP_STATUS status = adapter_grp_manager.adapter_group_join(session, group_identity, as_member);
  102. return status;
  103. }
  104. /*************************************************************************************************
  105. * Group query functions
  106. *************************************************************************************************/
  107. DYNAMIC_API PEP_STATUS adapter_group_query_groups(PEP_SESSION session, identity_list **groups)
  108. {
  109. pEpLog("called");
  110. PEP_STATUS status = adapter_grp_manager.group_query_groups(session, groups);
  111. return status;
  112. }
  113. DYNAMIC_API PEP_STATUS adapter_group_query_manager(PEP_SESSION session, const pEp_identity *const group, pEp_identity **manager)
  114. {
  115. pEpLog("called");
  116. PEP_STATUS status = adapter_grp_manager.group_query_manager(session, group, manager);
  117. return status;
  118. }
  119. DYNAMIC_API PEP_STATUS adapter_group_query_members(
  120. PEP_SESSION session,
  121. const pEp_identity *const group,
  122. identity_list **members)
  123. {
  124. pEpLog("called");
  125. PEP_STATUS status = adapter_grp_manager.group_query_members(session, group, members);
  126. return status;
  127. }
  128. #ifdef __cplusplus
  129. }
  130. #endif