iberbox  2.1.0
action.h
Go to the documentation of this file.
1 
10 #ifndef ACTION_H
11 #define ACTION_H
12 
13 #include "iberbox/config.h"
14 #include "iberbox/ownership.h"
15 #include "iberbox/error.h"
16 #include "iberbox/node.h"
17 #include "iberbox/transfer.h"
18 #include "iberbox/payments.h"
19 #include "iberbox/account.h"
20 #include "iberbox/user.h"
21 
22 #include <memory>
23 #include <functional>
24 #include <mutex>
25 #include <condition_variable>
26 
27 #ifdef USE_SCAPIX
28 #include <scapix/bridge/object.h>
29 #endif
30 
31 namespace iberbox {
32 
33 class ActionData;
34 typedef std::shared_ptr<ActionData> Action;
35 typedef std::vector<Action> ActionDataList;
36 typedef std::shared_ptr<ActionDataList> ActionList;
37 
42 #ifdef USE_SCAPIX
43  : public scapix::bridge::object<ActionData>
44 #endif
45 {
46 public:
51  {
52  TEST,
159  };
160 
166  {
170  };
171 
178  static const char *getTypeName(unsigned type)
179  {
180  static const char *sActionNames[] =
181  {
182  "TEST",
183  "ADD_CONTACT",
184  "VERIFY_EMAIL",
185  "FORGOT_PASSWORD",
186  "CREATE_ACCOUNT",
187  "CHANGE_PASSWORD",
188  "RECOVERY_KEY",
189  "MANAGE_2FA",
190  "LOGIN",
191  "GET_NODES",
192  "GET_ROOT",
193  "GET_CHILDREN",
194  "GET_NODE",
195  "GET_PATH",
196  "ADD_NODES",
197  "DELETE_NODE",
198  "RENAME_NODE",
199  "MOVE_NODE",
200  "COPY_NODE",
201  "CREATE_LINK",
202  "GET_LINK_INFO",
203  "USER_INFO",
204  "ACCOUNT_INFO",
205  "LOG_EVENT",
206  "TEST_PROXY",
207  "SET_PROXY",
208  "UPLOAD",
209  "DOWNLOAD",
210  "DOWNLOAD_ZIP",
211  "STREAM",
212  "BACKUP",
213  "UPLOAD_METADATA",
214  "DOWNLOAD_METADATA",
215  "GET_TRANSFERS",
216  "CLEAR_FINISHED_TRANSFERS",
217  "CANCEL_TRANSFERS",
218  "SET_TRANSFER_SPEED_LIMIT",
219  "GET_TRANSFER_SPEED_LIMIT",
220  "REGISTER_DEVICE",
221  "SELECT_DEVICE",
222  "GET_CURRENT_DEVICE",
223  "GET_DEVICE",
224  "GET_DEVICES",
225  "RENAME_DEVICE",
226  "DELETE_DEVICE",
227  "GET_BACKUP",
228  "GET_BACKUPS",
229  "CREATE_BACKUP",
230  "MODIFY_BACKUP",
231  "RENAME_BACKUP",
232  "CHANGE_BACKUP_SCHEDULE",
233  "CHANGE_BACKUP_PATH",
234  "CHANGE_BACKUP_STATUS",
235  "DELETE_BACKUP",
236  "AUTHORIZE_BACKUP",
237  "GET_SNAPSHOTS",
238  "GET_NEXT_SNAPSHOTS",
239  "GET_NEXT_SNAPSHOTS_BY_DEVICE",
240  "GET_NEXT_SNAPSHOTS_BY_BACKUP",
241  "GET_NEXT_SNAPSHOTS_BY_ACCOUNT",
242  "GET_NEXT_SNAPSHOTS_BY_SCHEDULE",
243  "GET_LAST_SNAPSHOTS",
244  "GET_LAST_SNAPSHOTS_BY_DEVICE",
245  "GET_LAST_SNAPSHOTS_BY_BACKUP",
246  "GET_LAST_SNAPSHOTS_BY_ACCOUNT",
247  "CREATE_INBOX",
248  "SET_INBOX_INFO",
249  "GET_INBOX_INFO",
250  "LOGIN_LINK",
251  "SET_RECORD_INFO",
252  "UPLOAD_TO_RECORD",
253  "REMOVE_FROM_RECORD",
254  "GET_RECORD_INFO",
255  "SET_RECORD_STATUS",
256  "SUBSCRIPTION_OPTIONS",
257  "PAYMENT_INFO",
258  "REMOVE_PAYMENT_METHOD",
259  "SET_INVOICING_ADDRESS",
260  "INVOICING_INFO",
261  "GET_INVOICE",
262  "SESSION_INFO",
263  "LOGOUT_LINK",
264  "CRASH_REPORT",
265  "UPDATE",
266  "LOGOUT",
267  "CURRENT_EMAIL",
268  "NEW_SESSION",
269  "DESTROY",
270  "REFERRALS_INFO",
271  "BALANCES_INFO",
272  "COUPONS",
273  "ADD_PAYMENT_METHOD",
274  "JOIN_LINK",
275  "DEFAULT_ACCOUNT",
276  "REVOKE_ACCOUNT_ACCESS",
277  "MANAGE_SECRETS",
278  "MANAGE_CONTACTS",
279  "MANAGE_OUTBOXES",
280  "MANAGE_SENT_RECORDS",
281  "GET_NODE_TREE",
282  "SET_ACCOUNT_VALUE",
283  "DELETE_ACCOUNT",
284  "SET_ACCESS_LEVEL",
285  "MANAGE_SHARED_DRIVES",
286  "DELETE_LINK",
287  "MANAGE_MEETINGS",
288  };
289  static_assert((sizeof(sActionNames) / sizeof(sActionNames[0]) == ActionData::LAST), "Invalid number of action names");
290  return type < ActionData::LAST ? sActionNames[type] : "INVALID";
291  }
292 
299  static const std::string getTypeNameString(unsigned type)
300  {
301  return getTypeName(type);
302  }
303 
304  virtual ~ActionData();
305 
311  int getLocalTag() const;
317  int getType() const;
322  int getTag() const;
327  const char *getActionName() const;
332  const std::string getActionNameString() const;
337  const char *getEmail() const;
342  const std::string getEmailString() const;
347  const char *getPassword() const;
352  const std::string getPasswordString() const;
357  const char *getText() const;
362  const std::string getTextString() const;
367  const char *getSession() const;
372  const std::string getSessionString() const;
377  const char *getName() const;
382  const std::string getNameString() const;
387  const char *getLastName() const;
392  const std::string getLastNameString() const;
397  const char *getLink() const;
402  const std::string getLinkString() const;
408  bool isProcessed() const;
414  bool isFinished() const;
415 
420  int getIntValue() const;
425  int getStatus() const;
430  long getLongValue() const;
435  uint64_t getTotalSize() const;
440  uint64_t getCompletedSize() const;
445  uint64_t getAccountId() const;
455  const std::string getAccountStringHandle() const;
460  uint64_t getUserId() const;
465  Node getNode() const;
470  NodeList getNodeList() const;
475  Transfer getTransfer() const;
480  uint64_t getNodeId() const;
485  NodeHandle getNodeHandle() const;
490  uint64_t getParentId() const;
495  NumberList getNumberList() const;
500  StringList getStringList() const;
510  ActionList getActionList() const;
520  PaymentInfo getPaymentInfo() const;
525  AccountInfo getAccountInfo() const;
530  UserInfo getUserInfo() const;
555  CouponInfoList getCoupons() const;
560  CouponInfo getCoupon() const;
575  std::vector<uint8_t> *getData();
580  int getErrorType() const;
585  const char *getErrorName() const;
590  const std::string getErrorNameString() const;
591 
596  const std::string getCustomData() const;
597 
598 #ifndef USE_SCAPIX
599 
603  Error getError() const;
604 #endif
605 
606 #ifndef EMSCRIPTEN
607 protected:
608 #endif
609 
610  ActionData(int type);
611 
612  int mLocalTag;
613  int mType;
614  int mTag;
615  char *mEmail;
616  char *mPassword;
617  char *mText;
618  char *mSession;
619  char *mName;
620  char *mLastName;
621  char *mLink;
622  bool mFinished;
623  bool mProcessed;
624  Error mError;
625 
626  int mIntValue;
627  int mStatus;
628  long mLongValue;
629  uint64_t mTotalSize;
630  uint64_t mCompletedSize;
631  uint64_t mAccountId;
632  std::string mAccountHandle;
633  uint64_t mUserId;
634  std::string mUserHandle;
635 
636  Node mNode;
637  NodeList mNodeList;
638  uint64_t mNodeId;
639  uint64_t mParentId;
640  std::string mNodeHandle;
641  std::string mParentHandle;
642  Transfer mTransfer;
643  std::vector<uint8_t> mData;
644 
645  NumberList mNumberList;
646  StringList mStringList;
647  TransferList mTransferList;
648  ActionList mActionList;
649  SubscriptionInfoList mSubscriptionInfoList;
650  PaymentInfo mPaymentInfo;
651  AccountInfo mAccountInfo;
652  UserInfo mUserInfo;
653  InvoicingInfo mInvoicingInfo;
654  SessionInfoList mActiveSessionInfoList;
655  SessionInfoList mInactiveSessionInfoList;
656  BalancesInfo mBalancesInfo;
657  CouponInfo mCouponInfo;
658  CouponInfoList mCouponInfoList;
659  PermissionInfoList mAccountPermissionInfoList;
660  PermissionInfoList mUserPermissionInfoList;
661  std::string mCustomData;
662 };
663 
667 class ActionListener : public SharedOwnership
668 #ifdef USE_SCAPIX
669  , public scapix::bridge::object<ActionListener>
670 #endif
671 {
672 public:
676  ActionListener();
681  ActionListener(std::function<void(Action)> finishCallback);
682  ActionListener(std::function<void(Action)> progressCallback, std::function<void(Action)> finishCallback);
683  ActionListener(std::function<void(Action)> errorCallback, std::function<void(Action)> progressCallback, std::function<void(Action)> finishCallback);
684  ActionListener(std::function<void(Action)> startCallback, std::function<void(Action)> errorCallback, std::function<void(Action)> progressCallback, std::function<void(Action)> finishCallback);
685 
686  virtual ~ActionListener();
687 
688  void setStartCallback(std::function<void(Action)> startCallback);
689  void setErrorCallback(std::function<void(Action)> errorCallback);
690  void setProgressCallback(std::function<void(Action)> progressCallback);
691  void setFinishCallback(std::function<void(Action)> finishCallback);
692 
697  virtual void onActionStart(Action action);
702  virtual void onActionProcessed(Action action);
707  virtual void onActionProgress(Action action);
712  virtual void onActionError(Action action);
717  virtual void onActionFinish(Action action);
718 
719 protected:
720  std::function<void(Action)> mStartCallback;
721  std::function<void(Action)> mProgressCallback;
722  std::function<void(Action)> mFinishCallback;
723  std::function<void(Action)> mErrorCallback;
724 };
725 
730 {
731 public:
741  virtual ~BlockingActionListener() override;
742 
747  virtual void onActionFinish(Action action) override;
752  virtual void onActionProgress(Action action) override;
758  virtual void setOwnership(bool external_or_cpp) override;
763  Action getResult();
764 
765 protected:
766  Action mAction;
767  bool mOwnMemory;
768 
769 #ifndef EMSCRIPTEN
770  std::condition_variable mConditionVariable;
771  std::mutex mMutex;
772 #endif
773 };
774 
775 #ifdef USE_SCAPIX
776 typedef std::shared_ptr<ActionListener> ActionListenerType;
777 #else
779 #endif
780 
781 }
782 
783 #endif // ACTION_H
784 
std::shared_ptr< CouponInfoDataList > CouponInfoList
Definition: account.h:337
uint64_t getNodeId() const
Gets the node identifier.
StringList getStringList() const
Gets the string list.
Definition: action.h:85
Definition: action.h:101
Definition: action.h:79
Definition: action.h:136
std::shared_ptr< BalancesInfoData > BalancesInfo
Definition: account.h:302
Transfer getTransfer() const
Gets the transfer.
Change password action.
Definition: action.h:57
The Blocking Action Listener class.
Definition: action.h:729
Copy node action.
Definition: action.h:70
SessionInfoList getActiveSessions() const
Gets the active sessions.
Definition: action.h:96
Get node action.
Definition: action.h:64
const char * getActionName() const
Gets the name of the action.
Error getError() const
Gets the error.
Definition: action.h:117
uint64_t getParentId() const
Gets the parent node identifier.
Definition: action.h:153
const std::string getTextString() const
Gets the text.
The iberbox namespace.
Definition: task.h:21
Definition: action.h:99
Definition: action.h:133
Get nodes action.
Definition: action.h:61
Get the tree of descendants of a node.
Definition: action.h:151
Definition: action.h:121
int getIntValue() const
Gets the int value.
Definition: action.h:118
Definition: action.h:141
uint64_t getAccountId() const
Gets the account identifier.
std::shared_ptr< InvoicingInfoData > InvoicingInfo
Definition: payments.h:300
uint64_t getUserId() const
Gets the user identifier.
const char * getSession() const
Gets the session.
Get children action.
Definition: action.h:63
Account info actions.
Definition: action.h:74
Test action.
Definition: action.h:52
const char * getLink() const
Gets the link.
ActionListener * ActionListenerType
Definition: action.h:778
uint64_t NodeHandle
Definition: node.h:27
const char * getPassword() const
Gets the password.
Definition: action.h:131
CouponInfoList getCoupons() const
Gets the coupons.
bool isFinished() const
Gets whether the action is finished or not.
NodeList getNodeList() const
Gets the node list.
const std::string getCustomData() const
Get custom data set by the app.
Add contact action.
Definition: action.h:53
Definition: action.h:124
const std::string getAccountStringHandle() const
Gets the account string handle.
PermissionInfoList getAccountPermissions() const
Gets the permissions a user has in every joined account.
const char * getLastName() const
Gets the last name.
NodeHandle getNodeHandle() const
Gets the node identifier.
long getLongValue() const
Gets the long value.
std::shared_ptr< AccountInfoData > AccountInfo
Definition: account.h:218
std::shared_ptr< NodeData > Node
Definition: node.h:631
Definition: action.h:158
Move node action.
Definition: action.h:69
Definition: action.h:134
SubscriptionInfoList getSubscriptionInfoList() const
Gets the subscription info list.
std::vector< Action > ActionDataList
Definition: action.h:35
Definition: action.h:138
Delete node action.
Definition: action.h:67
const std::string getActionNameString() const
Gets the name of the action.
Definition: action.h:80
const std::string getPasswordString() const
Gets the password.
Manage secret spaces.
Definition: action.h:147
AccountInfo getAccountInfo() const
Gets the account info.
Definition: action.h:119
The Action Data class.
Definition: action.h:41
TransferList getTransferList() const
Gets the transfer list.
Manage contacts.
Definition: action.h:148
BalancesInfo getBalancesInfo() const
Gets the balances info.
std::shared_ptr< PermissionInfoDataList > PermissionInfoList
Definition: account.h:363
ActionType
The action type enum.
Definition: action.h:50
Forgot password action.
Definition: action.h:55
Definition: action.h:91
const std::string getLinkString() const
Gets the link.
std::vector< uint8_t > * getData()
Gets the data.
Definition: action.h:120
Get path aciton.
Definition: action.h:65
Create and check join links as well as joining an account.
Definition: action.h:144
ActionList getActionList() const
Gets the action list.
std::shared_ptr< PaymentInfoData > PaymentInfo
Definition: payments.h:215
uint64_t getTotalSize() const
Gets the total size.
Definition: action.h:78
Revoke account access.
Definition: action.h:146
std::shared_ptr< NodeDataList > NodeList
Definition: node.h:633
PermissionInfoList getUserPermissions() const
Gets the permissions every joined user has for the current account.
Definition: action.h:81
const std::string getNameString() const
Gets the name.
const std::string getLastNameString() const
Gets the last name.
Manage shared drives.
Definition: action.h:155
const char * getName() const
Gets the name.
std::shared_ptr< TransferData > Transfer
Definition: transfer.h:238
Create link action.
Definition: action.h:71
Definition: action.h:76
InvoicingInfo getInvoicingInfo() const
Gets the invoicing info.
Definition: action.h:82
const char * getText() const
Gets the text.
Definition: action.h:58
Definition: action.h:139
Definition: action.h:135
std::shared_ptr< UserInfoData > UserInfo
The user info type.
Definition: user.h:105
std::shared_ptr< ActionData > Action
Definition: action.h:33
std::shared_ptr< StringVector > StringList
Definition: node.h:639
Definition: action.h:75
bool isProcessed() const
Gets whether the action is processed or not.
Add nodea action.
Definition: action.h:66
Definition: action.h:105
Definition: action.h:127
std::shared_ptr< TransferDataList > TransferList
Definition: transfer.h:240
Definition: action.h:97
Definition: action.h:93
int getTag() const
Gets the Tag object.
int getErrorType() const
Gets the error type.
Get root nodes action.
Definition: action.h:62
Rename node action.
Definition: action.h:68
Node getNode() const
Gets the node.
Manage outboxes.
Definition: action.h:149
const char * getEmail() const
Gets the email.
const char * getErrorName() const
Gets the error name.
Verify email action.
Definition: action.h:54
Definition: action.h:168
const std::string getSessionString() const
Gets the session.
Definition: action.h:137
The error class.
Definition: error.h:25
int getLocalTag() const
Gets the local tag of an action.
Definition: action.h:107
Get link info action.
Definition: action.h:72
Definition: action.h:167
std::shared_ptr< CouponInfoData > CouponInfo
Definition: account.h:335
std::shared_ptr< SessionInfoDataList > SessionInfoList
Definition: account.h:224
Manage sent records.
Definition: action.h:150
CouponInfo getCoupon() const
Gets the coupon.
const std::string getErrorNameString() const
Gets the error name.
Definition: action.h:140
std::shared_ptr< ActionDataList > ActionList
Definition: action.h:36
NumberList getNumberList() const
Gets the number list.
Definition: action.h:60
Definition: action.h:132
Definition: action.h:59
PaymentInfo getPaymentInfo() const
Gets the payment info.
Definition: action.h:98
Definition: action.h:94
uint64_t getCompletedSize() const
Gets the completed size.
Definition: action.h:142
static const std::string getTypeNameString(unsigned type)
Gets the event type name.
Definition: action.h:299
Replace default account.
Definition: action.h:145
std::shared_ptr< SubscriptionInfoDataList > SubscriptionInfoList
Definition: payments.h:28
Definition: action.h:100
Manage2faOperation
The manage 2-Factor Authentication operation enum.
Definition: action.h:165
Definition: action.h:157
User info actions.
Definition: action.h:73
int getStatus() const
Gets the status.
static const char * getTypeName(unsigned type)
Gets the event type name.
Definition: action.h:178
The Action Listener class.
Definition: action.h:667
int getType() const
Gets the type of the action.
Create account action.
Definition: action.h:56
NodeHandle getAccountHandle() const
Gets the account handle.
SessionInfoList getInactiveSessions() const
Gets the inactive sessions.
Definition: action.h:130
std::shared_ptr< NumberVector > NumberList
Definition: node.h:636
Definition: action.h:77
const std::string getEmailString() const
Gets the email.
Definition: action.h:95
Definition: action.h:169
UserInfo getUserInfo() const
Gets the user info.
Set a configuration value of the account.
Definition: action.h:152
Definition: action.h:156