Skip to content

Commit

Permalink
Clearer types in code rather than void pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
teusbenschop committed Jan 7, 2024
1 parent 662046a commit 814e74b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 20 deletions.
13 changes: 5 additions & 8 deletions database/ipc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ using namespace std;
// Database resilience: Stored in plain file system.


Database_Ipc::Database_Ipc (void * webserver_request_in)
Database_Ipc::Database_Ipc (Webserver_Request& webserver_request):
m_webserver_request (webserver_request)
{
webserver_request = webserver_request_in;
}


Expand Down Expand Up @@ -143,8 +143,7 @@ void Database_Ipc::deleteMessage (int id)

string Database_Ipc::getFocus ()
{
Webserver_Request * request = static_cast<Webserver_Request *>(webserver_request);
string user = request->session_logic ()->currentUser ();
string user = m_webserver_request.session_logic ()->currentUser ();

int highestId = 0;
string hitMessage = "";
Expand All @@ -171,8 +170,7 @@ string Database_Ipc::getFocus ()

Database_Ipc_Message Database_Ipc::getNote ()
{
Webserver_Request * request = static_cast<Webserver_Request *>(webserver_request);
string user = request->session_logic ()->currentUser ();
string user = m_webserver_request.session_logic ()->currentUser ();

int highestId = 0;
string hitMessage = "";
Expand Down Expand Up @@ -203,8 +201,7 @@ Database_Ipc_Message Database_Ipc::getNote ()

bool Database_Ipc::getNotesAlive ()
{
Webserver_Request * request = static_cast<Webserver_Request *>(webserver_request);
string user = request->session_logic ()->currentUser ();
string user = m_webserver_request.session_logic ()->currentUser ();

int highestId = 0;
string hitMessage = "";
Expand Down
7 changes: 5 additions & 2 deletions database/ipc.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include <config/libraries.h>


class Webserver_Request;


struct Database_Ipc_Item
{
std::string file {};
Expand All @@ -45,7 +48,7 @@ struct Database_Ipc_Message
class Database_Ipc
{
public:
Database_Ipc (void * webserver_request_in);
Database_Ipc (Webserver_Request& webserver_request);
void trim ();
void storeMessage (std::string user, std::string channel, std::string command, std::string message);
Database_Ipc_Message retrieveMessage (int id, std::string user, std::string channel, std::string command);
Expand All @@ -54,7 +57,7 @@ class Database_Ipc
Database_Ipc_Message getNote ();
bool getNotesAlive ();
private:
void * webserver_request {nullptr};
Webserver_Request& m_webserver_request;
std::string folder ();
std::string file (std::string file);
std::vector <Database_Ipc_Item> readData ();
Expand Down
2 changes: 1 addition & 1 deletion database/maintenance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void database_maintenance ()
database_bibles.optimize ();


Database_Ipc database_ipc = Database_Ipc (&webserver_request);
Database_Ipc database_ipc (webserver_request);
database_ipc.trim ();


Expand Down
17 changes: 9 additions & 8 deletions unittests/ipc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,16 @@ TEST (database, ipc)
// Test trim.
{
refresh_sandbox (false);
Database_Ipc database_ipc = Database_Ipc (nullptr);
Webserver_Request webserver_request;
Database_Ipc database_ipc (webserver_request);
database_ipc.trim ();
}

// Test store retrieve
{
refresh_sandbox (true);
Webserver_Request request;
Database_Ipc database_ipc = Database_Ipc (&request);
Webserver_Request webserver_request;
Database_Ipc database_ipc (webserver_request);

int id = 1;
string user = "phpunit";
Expand All @@ -103,8 +104,8 @@ TEST (database, ipc)
// Test delete
{
refresh_sandbox (true);
Webserver_Request request;
Database_Ipc database_ipc = Database_Ipc (&request);
Webserver_Request webserver_request;
Database_Ipc database_ipc (webserver_request);

int id = 1;
string user = "phpunit";
Expand All @@ -129,7 +130,7 @@ TEST (database, ipc)
Database_Users database_users;
database_users.create ();
Webserver_Request webserver_request;
Database_Ipc database_ipc (std::addressof(webserver_request));
Database_Ipc database_ipc (webserver_request);

string user = "phpunit";
webserver_request.session_logic ()->set_username (user);
Expand All @@ -156,7 +157,7 @@ TEST (database, ipc)
Database_Users database_users;
database_users.create ();
Webserver_Request webserver_request;
Database_Ipc database_ipc (std::addressof(webserver_request));
Database_Ipc database_ipc (webserver_request);

string user = "phpunit";
webserver_request.session_logic ()->set_username (user);
Expand All @@ -183,7 +184,7 @@ TEST (database, ipc)
Database_Users database_users;
database_users.create ();
Webserver_Request webserver_request;
Database_Ipc database_ipc (std::addressof(webserver_request));
Database_Ipc database_ipc (webserver_request);

string user = "phpunit";
webserver_request.session_logic ()->set_username (user);
Expand Down
3 changes: 2 additions & 1 deletion webserver/request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ Database_Check * Webserver_Request::database_check ()

Database_Ipc * Webserver_Request::database_ipc ()
{
if (!database_ipc_instance) database_ipc_instance = new Database_Ipc (this);
if (!database_ipc_instance)
database_ipc_instance = new Database_Ipc (*this);
return database_ipc_instance;
}

Expand Down

0 comments on commit 814e74b

Please sign in to comment.