1
0

textfeed.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #include <precomp.h>
  2. #include "textfeed.h"
  3. #include <bfc/pair.h>
  4. int TextFeed::registerFeed(const wchar_t *feedid, const wchar_t *initial_text, const wchar_t *description)
  5. {
  6. //if (feeds.getItem(StringW(feedid)))
  7. // return FALSE;
  8. auto it = feeds.find(feedid);
  9. if (feeds.end() != it)
  10. {
  11. return FALSE;
  12. }
  13. //std::pair<std::wstring, std::wstring> pair(initial_text, description);
  14. feeds.insert({ feedid, {initial_text, description} });
  15. dependent_sendEvent(svc_textFeed::depend_getClassGuid(), Event_TEXTCHANGE, (intptr_t)feedid, (void*)initial_text, wcslen(initial_text) + 1);
  16. return TRUE;
  17. }
  18. int TextFeed::sendFeed(const wchar_t *feedid, const wchar_t *text)
  19. {
  20. //Pair <StringW, StringW> ft(L"", L"");
  21. //if (!feeds.getItem(StringW(feedid), &ft))
  22. //{
  23. // //CUT ASSERTALWAYS("hey, you're trying to send a feed you didn't register. stop it.");
  24. // DebugString("TextFeed::sendFeed(), feedid '%s' not registered", feedid);
  25. // return FALSE;
  26. //}
  27. auto it = feeds.find(feedid);
  28. if (feeds.end() == it)
  29. {
  30. return FALSE;
  31. }
  32. //StringW id(feedid);
  33. //feeds.getItem(id, &ft);
  34. //ft.a = StringW(text);
  35. //feeds.setItem(StringW(feedid), ft);
  36. auto &ft = feeds[feedid];
  37. ft.first = text;
  38. dependent_sendEvent(svc_textFeed::depend_getClassGuid(), Event_TEXTCHANGE, (intptr_t)feedid, (void*)text, wcslen(text) + 1);
  39. return TRUE;
  40. }
  41. const wchar_t *TextFeed::getFeedText(const wchar_t *name)
  42. {
  43. //const Pair<StringW, StringW> *ft = feeds.getItemRef(StringW(name));
  44. //if (ft == NULL)
  45. // return NULL;
  46. //ft->a.getValue();
  47. auto it = feeds.find(name);
  48. if (it == feeds.end())
  49. {
  50. return NULL;
  51. }
  52. auto& ft = it->second;
  53. return ft.first.c_str();
  54. }
  55. const wchar_t *TextFeed::getFeedDescription(const wchar_t *name)
  56. {
  57. //const Pair<StringW, StringW> *ft = feeds.getItemRef(StringW(name));
  58. //if (ft == NULL) return NULL;
  59. //return ft->b.getValue();
  60. auto it = feeds.find(name);
  61. if (it == feeds.end())
  62. {
  63. return NULL;
  64. }
  65. auto& ft = it->second;
  66. return ft.second.c_str();
  67. }
  68. int TextFeed::hasFeed(const wchar_t *name)
  69. {
  70. return feeds.count(name);
  71. }
  72. void TextFeed::dependent_onRegViewer(api_dependentviewer *viewer, int add)
  73. {
  74. if (add)
  75. {
  76. //for (int i = 0; i < feeds.getNumItems(); i++)
  77. //{
  78. // StringW a = feeds.enumIndexByPos(i, StringW(L""));
  79. // Pair<StringW, StringW> sp(L"", L"");
  80. // StringW b = feeds.enumItemByPos(i, sp).a;
  81. // dependent_sendEvent(svc_textFeed::depend_getClassGuid(), Event_TEXTCHANGE, (intptr_t)a.getValue(), (void*)b.getValue(), b.len() + 1, viewer); //send to this viewer only
  82. //}
  83. for (auto it = feeds.begin(); it != feeds.end(); it++)
  84. {
  85. std::wstring key = it->first;
  86. auto val = it->second;
  87. std::wstring val_first = val.first;
  88. dependent_sendEvent(svc_textFeed::depend_getClassGuid(), Event_TEXTCHANGE, (intptr_t)key.c_str(), (void*)val_first.c_str(), wcslen(val_first.c_str()) + 1, viewer); //send to this viewer only
  89. }
  90. }
  91. if (add) onRegClient();
  92. else onDeregClient();
  93. }
  94. void *TextFeed::dependent_getInterface(const GUID *classguid)
  95. {
  96. HANDLEGETINTERFACE(svc_textFeed);
  97. return NULL;
  98. }