Skip to content
Permalink
Browse files

Added ModEvent and UserEvent objects

  • Loading branch information...
Turupawn committed Mar 12, 2019
1 parent d98dcf8 commit 04cc910ba715a392e054ba85cf4b3cd45f78867d
Showing with 270 additions and 104 deletions.
  1. +1 −1 examples/code-samples/c++/31_EventsListener.cpp
  2. +1 −1 examples/code-samples/c++/32_GetModEvents.cpp
  3. +1 −1 examples/code-samples/c++/33_GetAllModEvents.cpp
  4. +1 −1 examples/code-samples/c++/41_GetUserEvents.cpp
  5. +1 −1 examples/code-samples/c/31_EventsListener.c
  6. +1 −1 examples/code-samples/c/32_GetModEvents.c
  7. +1 −1 examples/code-samples/c/33_GetAllModEvents.c
  8. +1 −1 examples/code-samples/c/41_GetUserEvents.c
  9. +25 −14 examples/code-samples/c/modio_c.h
  10. +1 −1 include/Globals.h
  11. +2 −0 include/ModioUtility.h
  12. +6 −5 include/c++/ModIOInstance.h
  13. +2 −2 include/c++/methods/callbacks/MeInstanceCallbacks.h
  14. +6 −6 include/c++/methods/callbacks/ModEventsInstanceCallbacks.h
  15. +4 −4 include/c++/schemas/{Event.h → ModEvent.h}
  16. +25 −0 include/c++/schemas/UserEvent.h
  17. +25 −14 include/c/ModioC.h
  18. +2 −2 include/c/methods/callbacks/MeCallbacks.h
  19. +3 −3 include/c/methods/callbacks/ModEventCallbacks.h
  20. +2 −2 include/c/schemas/{ModioEvent.h → ModioModEvent.h}
  21. +13 −0 include/c/schemas/ModioUserEvent.h
  22. +2 −1 include/modio.h
  23. +1 −1 src/Globals.cpp
  24. +22 −3 src/ModioUtility.cpp
  25. +1 −1 src/c++/methods/MeInstanceMethods.cpp
  26. +3 −3 src/c++/methods/ModEventInstanceMethods.cpp
  27. +2 −2 src/c++/methods/callbacks/MeInstanceCallbacks.cpp
  28. +6 −6 src/c++/methods/callbacks/ModEventsInstanceCallbacks.cpp
  29. +3 −3 src/c++/schemas/{Event.cpp → ModEvent.cpp}
  30. +28 −0 src/c++/schemas/UserEvent.cpp
  31. +1 −1 src/c/methods/MeMethods.cpp
  32. +3 −3 src/c/methods/ModEventMethods.cpp
  33. +4 −4 src/c/methods/callbacks/MeCallbacks.cpp
  34. +8 −8 src/c/methods/callbacks/ModEventCallbacks.cpp
  35. +3 −3 src/c/schemas/{ModioEvent.cpp → ModioModEvent.cpp}
  36. +55 −0 src/c/schemas/ModioUserEvent.cpp
  37. +4 −4 test/test_modio.cpp
@@ -21,7 +21,7 @@ int main(void)
std::cout << "Listening to mod events..." << std::endl;

// You can register a function as callback for mod events
modio_instance.setEventListener([&](const modio::Response &response, const std::vector<modio::Event> &events) {
modio_instance.setEventListener([&](const modio::Response &response, const std::vector<modio::ModEvent> &events) {
// The mod event callback is triggered in a constant interval of time, 15 seconds by default
std::cout << "On event listener response: " << response.code << std::endl;
if (response.code == 200)
@@ -36,7 +36,7 @@ int main(void)
std::cout << "Getting events..." << std::endl;

// Everything is setup up, let's retreive the events now
modio_instance.getEvents(mod_id, filter, [&](const modio::Response &response, const std::vector<modio::Event> &events) {
modio_instance.getEvents(mod_id, filter, [&](const modio::Response &response, const std::vector<modio::ModEvent> &events) {
std::cout << "On get events response: " << response.code << std::endl;
if (response.code == 200)
{
@@ -31,7 +31,7 @@ int main(void)
std::cout << "Getting events..." << std::endl;

// Everything is setup up, let's retreive the events now
modio_instance.getAllEvents(filter, [&](const modio::Response &response, const std::vector<modio::Event> &events) {
modio_instance.getAllEvents(filter, [&](const modio::Response &response, const std::vector<modio::ModEvent> &events) {
std::cout << "On get events response: " << response.code << std::endl;
if (response.code == 200)
{
@@ -31,7 +31,7 @@ int main(void)
std::cout << "Getting events..." << std::endl;

// Everything is setup up, let's retreive the events now
modio_instance.getUserEvents(filter, [&](const modio::Response &response, const std::vector<modio::Event> &events) {
modio_instance.getUserEvents(filter, [&](const modio::Response &response, const std::vector<modio::UserEvent> &events) {
std::cout << "On user events response: " << response.code << std::endl;
if (response.code == 200)
{
@@ -1,6 +1,6 @@
#include "modio_c.h"

void onEvent(ModioResponse response, ModioEvent *events_array, u32 events_array_size)
void onEvent(ModioResponse response, ModioModEvent *events_array, u32 events_array_size)
{
// The mod event callback is triggered in a constant interval of time, 15 seconds by default
printf("Event listener response: %i\n", response.code);
@@ -1,7 +1,7 @@
#include "modio_c.h"
#include <time.h>

void onGetEvents(void *object, ModioResponse response, ModioEvent *events_array, u32 events_array_size)
void onGetEvents(void *object, ModioResponse response, ModioModEvent *events_array, u32 events_array_size)
{
bool *wait = object;
printf("On get mod events response: %i\n", response.code);
@@ -1,7 +1,7 @@
#include "modio_c.h"
#include <time.h>

void onGetAllEvents(void *object, ModioResponse response, ModioEvent *events_array, u32 events_array_size)
void onGetAllEvents(void *object, ModioResponse response, ModioModEvent *events_array, u32 events_array_size)
{
bool *wait = object;
printf("On get mod events response: %i\n", response.code);
@@ -1,7 +1,7 @@
#include "modio_c.h"
#include <time.h>

void onGetUserEvents(void *object, ModioResponse response, ModioEvent *events_array, u32 events_array_size)
void onGetUserEvents(void *object, ModioResponse response, ModioUserEvent *events_array, u32 events_array_size)
{
bool *wait = object;
printf("On get user events response: %i\n", response.code);
@@ -99,7 +99,6 @@ typedef struct ModioComment ModioComment;
typedef struct ModioDependency ModioDependency;
typedef struct ModioDownload ModioDownload;
typedef struct ModioError ModioError;
typedef struct ModioEvent ModioEvent;
typedef struct ModioFilehash ModioFilehash;
typedef struct ModioGame ModioGame;
typedef struct ModioGameTagOption ModioGameTagOption;
@@ -112,6 +111,7 @@ typedef struct ModioLogo ModioLogo;
typedef struct ModioMedia ModioMedia;
typedef struct ModioMetadataKVP ModioMetadataKVP;
typedef struct ModioMod ModioMod;
typedef struct ModioModEvent ModioModEvent;
typedef struct ModioModfile ModioModfile;
typedef struct ModioQueuedModDownload ModioQueuedModDownload;
typedef struct ModioQueuedModfileUpload ModioQueuedModfileUpload;
@@ -120,6 +120,7 @@ typedef struct ModioResponse ModioResponse;
typedef struct ModioStats ModioStats;
typedef struct ModioTag ModioTag;
typedef struct ModioUser ModioUser;
typedef struct ModioUserEvent ModioUserEvent;
// Creators
typedef struct ModioFilterCreator ModioFilterCreator;
typedef struct ModioModCreator ModioModCreator;
@@ -276,15 +277,6 @@ struct ModioError
u32 errors_array_size;
};

struct ModioEvent
{
u32 id;
u32 mod_id;
u32 user_id;
u32 event_type;
u32 date_added;
};

struct ModioFilehash
{
char* md5;
@@ -351,6 +343,15 @@ struct ModioMetadataKVP
char* metavalue;
};

struct ModioModEvent
{
u32 id;
u32 mod_id;
u32 user_id;
u32 event_type;
u32 date_added;
};

struct ModioModfile
{
u32 id;
@@ -469,6 +470,16 @@ struct ModioResponse
ModioError error;
};

struct ModioUserEvent
{
u32 id;
u32 game_id;
u32 mod_id;
u32 user_id;
u32 event_type;
u32 date_added;
};

//General Methods
void modioInit(u32 environment, u32 game_id, char* api_key, char* root_path);
void modioShutdown();
@@ -478,9 +489,9 @@ void modioSleep(u32 milliseconds);
void compressFiles(char* root_directory, char* filenames[], u32 filenames_size, char* zip_path);

//Events
void modioSetEventListener(void (*callback)(ModioResponse response, ModioEvent* events_array, u32 events_array_size));
void modioGetEvents(void* object, u32 mod_id, ModioFilterCreator filter, void (*callback)(void* object, ModioResponse response, ModioEvent* events_array, u32 events_array_size));
void modioGetAllEvents(void* object, ModioFilterCreator filter, void (*callback)(void* object, ModioResponse response, ModioEvent* events_array, u32 events_array_size));
void modioSetEventListener(void (*callback)(ModioResponse response, ModioModEvent* events_array, u32 events_array_size));
void modioGetEvents(void* object, u32 mod_id, ModioFilterCreator filter, void (*callback)(void* object, ModioResponse response, ModioModEvent* events_array, u32 events_array_size));
void modioGetAllEvents(void* object, ModioFilterCreator filter, void (*callback)(void* object, ModioResponse response, ModioModEvent* events_array, u32 events_array_size));

//Authentication methods
void modioEmailRequest(void* object, char* email, void (*callback)(void* object, ModioResponse response));
@@ -600,7 +611,7 @@ void modioFreeModEditor(ModioModEditor* update_mod_handler);
//Me Methods
void modioGetAuthenticatedUser(void* object, void (*callback)(void* object, ModioResponse response, ModioUser user));
void modioGetUserSubscriptions(void* object, ModioFilterCreator filter, void (*callback)(void* object, ModioResponse response, ModioMod mods[], u32 mods_size));
void modioGetUserEvents(void* object, ModioFilterCreator filter, void (*callback)(void* object, ModioResponse response, ModioEvent* events_array, u32 events_array_size));
void modioGetUserEvents(void* object, ModioFilterCreator filter, void (*callback)(void* object, ModioResponse response, ModioUserEvent* events_array, u32 events_array_size));
void modioGetUserGames(void* object, ModioFilterCreator filter, void (*callback)(void* object, ModioResponse response, ModioGame games[], u32 games_size));
void modioGetUserMods(void* object, ModioFilterCreator filter, void (*callback)(void* object, ModioResponse response, ModioMod mods[], u32 mods_size));
void modioGetUserModfiles(void* object, ModioFilterCreator filter, void (*callback)(void* object, ModioResponse response, ModioModfile modfiles[], u32 modfiles_size));
@@ -23,7 +23,7 @@ namespace modio
extern u32 BACKGROUND_DOWNLOADS;
extern u32 RETRY_AFTER;
extern ModioUser current_user;
extern void (*event_listener_callback)(ModioResponse response, ModioEvent* events_array, u32 events_array_size);
extern void (*event_listener_callback)(ModioResponse response, ModioModEvent* events_array, u32 events_array_size);
extern void (*download_callback)(u32 response_code, u32 mod_id);
extern void (*upload_callback)(u32 response_code, u32 mod_id);
extern nlohmann::json installed_mods;
@@ -7,6 +7,8 @@
#include "c/ModioC.h"
#include "c++/schemas/Mod.h"
#include "c++/schemas/Response.h"
#include "c/schemas/ModioUserEvent.h"
#include "c/schemas/ModioModEvent.h"

struct GenericRequestParams
{
@@ -17,7 +17,7 @@
#include "schemas/Media.h"
#include "schemas/MetadataKVP.h"
#include "schemas/Mod.h"
#include "schemas/Event.h"
#include "schemas/ModEvent.h"
#include "schemas/Modfile.h"
#include "schemas/Rating.h"
#include "schemas/Stats.h"
@@ -26,6 +26,7 @@
#include "schemas/Response.h"
#include "schemas/Tag.h"
#include "schemas/User.h"
#include "schemas/UserEvent.h"
#include "methods/callbacks/AuthenticationInstanceCallbacks.h"
#include "methods/callbacks/CommentsInstanceCallbacks.h"
#include "methods/callbacks/DependenciesInstanceCallbacks.h"
@@ -61,9 +62,9 @@ class MODIO_DLL Instance
void compressFiles(std::string root_directory, std::vector<std::string> filenames, std::string zip_path);

//Events
void getEvents(u32 mod_id, modio::FilterCreator &filter, const std::function<void(const modio::Response &, const std::vector<modio::Event> &events)> &callback);
void getAllEvents(modio::FilterCreator &filter, const std::function<void(const modio::Response &, const std::vector<modio::Event> &events)> &callback);
void setEventListener(const std::function<void(const modio::Response &, const std::vector<modio::Event> &events)> &callback);
void getEvents(u32 mod_id, modio::FilterCreator &filter, const std::function<void(const modio::Response &, const std::vector<modio::ModEvent> &events)> &callback);
void getAllEvents(modio::FilterCreator &filter, const std::function<void(const modio::Response &, const std::vector<modio::ModEvent> &events)> &callback);
void setEventListener(const std::function<void(const modio::Response &, const std::vector<modio::ModEvent> &events)> &callback);

//Authentication Methods
bool isLoggedIn() const;
@@ -118,7 +119,7 @@ class MODIO_DLL Instance
//Me Methods
void getAuthenticatedUser(const std::function<void(const modio::Response &response, const modio::User &user)> &callback);
void getUserSubscriptions(modio::FilterCreator &filter, const std::function<void(const modio::Response &response, const std::vector<modio::Mod> &mods)> &callback);
void getUserEvents(modio::FilterCreator &filter, const std::function<void(const modio::Response &, const std::vector<modio::Event> &events)> &callback);
void getUserEvents(modio::FilterCreator &filter, const std::function<void(const modio::Response &, const std::vector<modio::UserEvent> &events)> &callback);
void getUserGames(modio::FilterCreator &filter, const std::function<void(const modio::Response &response, const std::vector<modio::Game> &games)> &callback);
void getUserMods(modio::FilterCreator &filter, const std::function<void(const modio::Response &response, const std::vector<modio::Mod> &mods)> &callback);
void getUserModfiles(modio::FilterCreator &filter, const std::function<void(const modio::Response &response, const std::vector<modio::Modfile> &modfiles)> &callback);
@@ -12,7 +12,7 @@ struct GetUserSubscriptionsCall

struct GetUserEventsCall
{
const std::function<void(const modio::Response &response, std::vector<modio::Event> events)> callback;
const std::function<void(const modio::Response &response, std::vector<modio::UserEvent> events)> callback;
};

struct GetUserGamesCall
@@ -45,7 +45,7 @@ extern std::map<u32, GetUserRatingsCall *> get_user_ratings_calls;

void onGetAuthenticatedUser(void *object, ModioResponse modio_response, ModioUser modio_user);
void onGetUserSubscriptions(void *object, ModioResponse modio_response, ModioMod mods[], u32 mods_size);
void onGetUserEvents(void *object, ModioResponse modio_response, ModioEvent *events_array, u32 events_array_size);
void onGetUserEvents(void *object, ModioResponse modio_response, ModioUserEvent *events_array, u32 events_array_size);
void onGetUserGames(void *object, ModioResponse modio_response, ModioGame games[], u32 games_size);
void onGetUserMods(void *object, ModioResponse modio_response, ModioMod mods[], u32 mods_size);
void onGetUserModfiles(void *object, ModioResponse modio_response, ModioModfile modfiles[], u32 modfiles_size);
@@ -3,26 +3,26 @@ namespace modio
{
struct GetEventsCall
{
const std::function<void(const modio::Response &response, std::vector<modio::Event> events)> callback;
const std::function<void(const modio::Response &response, std::vector<modio::ModEvent> events)> callback;
};

struct GetAllEventsCall
{
const std::function<void(const modio::Response &response, std::vector<modio::Event> events)> callback;
const std::function<void(const modio::Response &response, std::vector<modio::ModEvent> events)> callback;
};

struct SetEventListenerCall
{
const std::function<void(const modio::Response &response, std::vector<modio::Event> events)> callback;
const std::function<void(const modio::Response &response, std::vector<modio::ModEvent> events)> callback;
};

extern std::map<u32, GetEventsCall *> get_events_calls;
extern std::map<u32, GetAllEventsCall *> get_all_events_calls;
extern SetEventListenerCall *set_event_listener_call;

void onGetEvents(void *object, ModioResponse modio_response, ModioEvent *events_array, u32 events_array_size);
void onGetAllEvents(void *object, ModioResponse modio_response, ModioEvent *events_array, u32 events_array_size);
void onSetEventListener(ModioResponse modio_response, ModioEvent *events_array, u32 events_array_size);
void onGetEvents(void *object, ModioResponse modio_response, ModioModEvent *events_array, u32 events_array_size);
void onGetAllEvents(void *object, ModioResponse modio_response, ModioModEvent *events_array, u32 events_array_size);
void onSetEventListener(ModioResponse modio_response, ModioModEvent *events_array, u32 events_array_size);

void clearModEventsRequestCalls();
} // namespace modio
@@ -2,11 +2,11 @@
#define MODIO_MODEVENT_H

#include "../../Globals.h"
#include "../../c/schemas/ModioEvent.h"
#include "../../c/schemas/ModioModEvent.h"

namespace modio
{
class Event
class ModEvent
{
public:
u32 id;
@@ -15,10 +15,10 @@ class Event
u32 event_type;
u32 date_added;

void initialize(ModioEvent event);
void initialize(ModioModEvent event);
};

extern nlohmann::json toJson(Event &event);
extern nlohmann::json toJson(ModEvent &event);
} // namespace modio

#endif
@@ -0,0 +1,25 @@
#ifndef MODIO_USEREVENT_H
#define MODIO_USEREVENT_H

#include "../../Globals.h"
#include "../../c/schemas/ModioUserEvent.h"

namespace modio
{
class UserEvent
{
public:
u32 id;
u32 game_id;
u32 mod_id;
u32 user_id;
u32 event_type;
u32 date_added;

void initialize(ModioUserEvent event);
};

extern nlohmann::json toJson(UserEvent &event);
} // namespace modio

#endif
Oops, something went wrong.

0 comments on commit 04cc910

Please sign in to comment.
You can’t perform that action at this time.