Advertisement
Guest User

Untitled

a guest
May 22nd, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. /*
  2. * Idea of this praposal is to come up with a notification mechanism from SDK to SDK consumer(App)
  3. * some notifications are fire and forget and some notifications needs feedback.
  4. * one use case is popups
  5. */
  6.  
  7. /*
  8. * SDK design
  9. */
  10.  
  11. #interface/ header file
  12. .....
  13. enum AlertResult
  14. {
  15. Handled,
  16. Ignored,
  17. ...
  18. }
  19.  
  20. enum AlertType
  21. {
  22. PopUpInfo,
  23. PopUPYesNo,
  24. PopUpYesNoCancel,
  25. WarningInfoToUser,
  26. HandleByDev..
  27. ....
  28. }
  29.  
  30. enum PopUpOption
  31. {
  32. Yes,
  33. No,
  34. Cancel
  35. }
  36.  
  37. enum FeedBackType
  38. {
  39. NoFeedback,
  40. popUpOption,
  41. other..
  42. }
  43.  
  44. Struct Feedback
  45. {
  46. FeedBackType feedbackType = FeedBackType::NoFeedback;
  47. }
  48.  
  49. struct PopupFeedback : public Feedback
  50. {
  51. PopupFeedback()
  52. {
  53. feedbackType = FeedBackType::FeedBackType;
  54. }
  55. PopUpOption Result;
  56. }
  57.  
  58. /*
  59. * we can make it mandaroty as this is the main way
  60. */
  61. void RegisterAlert( std::function<AlertResult( AlertType type, Feedback* feedback)> );
  62.  
  63. std::function<AlertResult( AlertType type, Feedback ) > m_FAlert;
  64. /////////////// Implementation SDK///////////////////////////
  65.  
  66.  
  67. ...
  68. ...
  69. if( m_FAlert )
  70. {
  71. std::unique_ptr<PopupFeedback> feedback = std::make_shared<PopupFeedback>();
  72. auto result = m_FAlert( AlertType::PopUpYesNoCancel, feedback.get() );
  73. // logic based on feedback /////
  74. }
  75.  
  76.  
  77. /////////////////////////////////////////////APP SIDE implementation ////////////////////////
  78. /*
  79. * this differs a bit on Android and IOS I am doing this in C++ for my convinience
  80. */
  81.  
  82. /*
  83. * Function that
  84. */
  85.  
  86. AlertResult AlertHandle( AlertType type, Feedback* feedbacktpSDK)
  87. {
  88. switch( type )
  89. {
  90. case PopUpInfo:
  91. {
  92.  
  93. }
  94. case PopUpYesNoCancel:
  95. {
  96. // pop up tp user
  97. feedbacktpSDK->result = // set the result
  98. }
  99. default:
  100.  
  101. }
  102. return Handled;
  103. }
  104.  
  105. /////////// set the Alert hander
  106. SDK->SetAlertHandler( [&](AlertType type, Feedback* feedbacktpSDK)->AlertHandle
  107. {
  108. return AlertHandle(type, feedbacktpSDK);
  109. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement