Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Idea of this praposal is to come up with a notification mechanism from SDK to SDK consumer(App)
- * some notifications are fire and forget and some notifications needs feedback.
- * one use case is popups
- */
- /*
- * SDK design
- */
- #interface/ header file
- .....
- enum AlertResult
- {
- Handled,
- Ignored,
- ...
- }
- enum AlertType
- {
- PopUpInfo,
- PopUPYesNo,
- PopUpYesNoCancel,
- WarningInfoToUser,
- HandleByDev..
- ....
- }
- enum PopUpOption
- {
- Yes,
- No,
- Cancel
- }
- enum FeedBackType
- {
- NoFeedback,
- popUpOption,
- other..
- }
- Struct Feedback
- {
- FeedBackType feedbackType = FeedBackType::NoFeedback;
- }
- struct PopupFeedback : public Feedback
- {
- PopupFeedback()
- {
- feedbackType = FeedBackType::FeedBackType;
- }
- PopUpOption Result;
- }
- /*
- * we can make it mandaroty as this is the main way
- */
- void RegisterAlert( std::function<AlertResult( AlertType type, Feedback* feedback)> );
- std::function<AlertResult( AlertType type, Feedback ) > m_FAlert;
- /////////////// Implementation SDK///////////////////////////
- ...
- ...
- if( m_FAlert )
- {
- std::unique_ptr<PopupFeedback> feedback = std::make_shared<PopupFeedback>();
- auto result = m_FAlert( AlertType::PopUpYesNoCancel, feedback.get() );
- // logic based on feedback /////
- }
- /////////////////////////////////////////////APP SIDE implementation ////////////////////////
- /*
- * this differs a bit on Android and IOS I am doing this in C++ for my convinience
- */
- /*
- * Function that
- */
- AlertResult AlertHandle( AlertType type, Feedback* feedbacktpSDK)
- {
- switch( type )
- {
- case PopUpInfo:
- {
- }
- case PopUpYesNoCancel:
- {
- // pop up tp user
- feedbacktpSDK->result = // set the result
- }
- default:
- }
- return Handled;
- }
- /////////// set the Alert hander
- SDK->SetAlertHandler( [&](AlertType type, Feedback* feedbacktpSDK)->AlertHandle
- {
- return AlertHandle(type, feedbacktpSDK);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement