Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Coffee corner » Strange Architecture (Dll Hot load)
Strange Architecture [message #52077] Tue, 16 July 2019 12:34 Go to next message
Xemuth is currently offline  Xemuth
Messages: 387
Registered: August 2018
Location: France
Senior Member
Hello Everyone,

with friends we are working on a projet made with Upp ! let me quickly explain it :

SmartUppBot is a bot made for discord programmed in C++ using Upp and jjacksonRIAB discord pacakge ( https://www.ultimatepp.org/forums/index.php?t=usrinfo&id =1150&)

Since we are many to work on and the objective was to learn Upp/C++, I have made a "SmartUppBot" package contening my SmartUppBot class and a mother class named "DiscordModule".
The main idea was, everyone who would like to work on the project would have to made a new package and inherite my mother class on is package. THen I just have to create an instance of the inherited class and add it to SmartUppBot.

Let me show you :
https://i.imgur.com/ToFcG0t.png

#include <Core/Core.h>
#include "SmartBotUpp.h"

#include <Discord_Overwatch/Discord_Overwatch.h>
#include <EasyConfiguration/EasyConfiguration.h>
#include <Discord_Minecraft/Discord_Minecraft.h>
#include <Discord_RNG/Discord_RNG.h>
#include <GraphBuilder/GraphBuilder.h>
using namespace Upp;
//Module OverWatch : https://github.com/Xemuth/Discord_Overwatch
//Module Minecraft : https://github.com/Xemuth/Discord_Minecraft
//Module RNG : https://github.com/Xemuth/Discord_RNG
//Module GraphBuilder : https://github.com/Xemuth/GraphBuilder
//EasyConfiguration : https://github.com/Xemuth/EasyConfiguration

CONSOLE_APP_MAIN {
	StdLogSetup(LOG_COUT|LOG_FILE);
	EasyConfiguration ez(R"(C:/discordTokens.txt)");
	if(ez.GetCount() >= 2){
		SmartBotUpp mybot(ez.GetValue<String>("BotId"),ez.GetValue<String>("BotToken"));
	
		Discord_Overwatch ow("OverWatch","ow");
		mybot.AddModule(&ow);
	
		Discord_Minecraft mc("Minecraft","mc");
		mybot.AddModule(&mc);
	
		Discord_RNG rng("RNG", "rng");
		mybot.AddModule(&rng);
		
		mybot.Launch();
	}else{
		LOG( "config file is incorrect !\n"); 	
	}
}

As you can see every "Discord_***" is a discord module inherited from mother class. Each module have is own discord command defined "!ow" ; "!rng" ; "!mc" ...
and the bot just loop modules for each message send on Discord.

This architecture work well but every time someone update is module I must recompile everything on Linux and send it to my RaspberryPi.
That's why I was wondering if it was possible to do something like this :
https://i.imgur.com/EG7sJu0.png

Is it possible to compile modules as Dll (or linux equivalent)
and Programme SmartUppBot to allowing it to "hot load" dll located on a file and use it ?
if yes. Do this system have a limit ? is it a good way to do "clean" programme ?

Thanks for the time you taken to read this.

Best regard.

Xemuth

[Updated on: Tue, 16 July 2019 16:14]

Report message to a moderator

Re: Strange Architecture [message #52089 is a reply to message #52077] Wed, 17 July 2019 20:14 Go to previous messageGo to next message
Novo is currently offline  Novo
Messages: 1358
Registered: December 2006
Ultimate Contributor
Xemuth wrote on Tue, 16 July 2019 06:34

Is it possible to compile modules as Dll (or linux equivalent)
and Programme SmartUppBot to allowing it to "hot load" dll located on a file and use it ?
if yes. Do this system have a limit ? is it a good way to do "clean" programme ?

The U++'s way of working with DLLs is this.
It looks like DLLs name should be known at compile time, but you should be able to improve this code if you want to.
In general, DLLs are loaded/unloaded via dlopen/dlclose calls (in Windows these functions have different names).
Useful tool: Dependency Walker.
Besides showing you what is imported/exported it allows you to trace DLL-related calls.
Try to trace any app and you'll have a lot of fun.

You can create DLLs in U++.
U++ itself is not very well suited to be shared among DLLs.
Hint: try to choose "All shared" in "Output mode" and check what will happen.

Hope this helps.


Regards,
Novo
Re: Strange Architecture [message #52095 is a reply to message #52077] Thu, 18 July 2019 14:45 Go to previous messageGo to next message
Xemuth is currently offline  Xemuth
Messages: 387
Registered: August 2018
Location: France
Senior Member
Hello Novo,

Thanks for your response !
I'm happy to figure my iea is maybe possible !
Quote:
In general, DLLs are loaded/unloaded via dlopen/dlclose calls (in Windows these functions have different names).

That's mean I can do near the same code between linux and windows ? or dll in windows and linux don't have same architecture ?

Have good day,
Best Regard.
Re: Strange Architecture [message #52097 is a reply to message #52095] Thu, 18 July 2019 16:57 Go to previous messageGo to next message
Novo is currently offline  Novo
Messages: 1358
Registered: December 2006
Ultimate Contributor
Xemuth wrote on Thu, 18 July 2019 08:45

That's mean I can do near the same code between linux and windows ? or dll in windows and linux don't have same architecture ?

Linux and Windows have similar architectures.
DLL-related functions have different names, but they do pretty much the same thing.
You just need to write a platform-independed wrapper for them.
This is a trivial task.
DLLs on Windows and Linux behave slightly differently.
Main source of information for you should be man ld.so
Read it carefully.
Other useful apps on Linux: ldd, nm.
Start with man ldd and man nm

Hope this helps.


Regards,
Novo

[Updated on: Fri, 19 July 2019 04:32]

Report message to a moderator

Re: Strange Architecture [message #52099 is a reply to message #52077] Fri, 19 July 2019 12:29 Go to previous messageGo to next message
Xemuth is currently offline  Xemuth
Messages: 387
Registered: August 2018
Location: France
Senior Member
Hello Novo,

I hadtry to load a custom dll I made. (used flag DLL)
then define a Dli file. getting the Function name by using Dependency walker Very Happy
and it worked ! Very Happy

but I tried :
Quote:
Hint: try to choose "All shared" in "Output mode" and check what will happen.

and just got error :
Creating library...
lld: error: unknown argument: -u
collect2.exe: error: ld returned 1 exit status

There were errors. (0:00.34)

I probably used it wrong. Can you explain me what's for ?

Thanks in advance.

Best regard.
Re: Strange Architecture [message #52104 is a reply to message #52099] Fri, 19 July 2019 17:38 Go to previous messageGo to next message
Novo is currently offline  Novo
Messages: 1358
Registered: December 2006
Ultimate Contributor
Xemuth wrote on Fri, 19 July 2019 06:29

I probably used it wrong. Can you explain me what's for ?

It is supposed to compile each U++ package as DLL. This works in Linux. It looks like this doesn't work in Windows.
If you can compile a package as DLL, you can link against this DLL and do not need to include all U++ into you own DLL.
This feature is not supported by U++ very well. This is one of limitations.


Regards,
Novo
Re: Strange Architecture [message #52105 is a reply to message #52077] Fri, 19 July 2019 18:12 Go to previous messageGo to next message
Xemuth is currently offline  Xemuth
Messages: 387
Registered: August 2018
Location: France
Senior Member
Thanks Novo,

you make thing more clear.
Re: Strange Architecture [message #55943 is a reply to message #52099] Tue, 05 January 2021 16:59 Go to previous messageGo to next message
JeyCi is currently offline  JeyCi
Messages: 50
Registered: July 2020
Member
Xemuth wrote on Fri, 19 July 2019 12:29
and just got error :
Creating library...
lld: error: unknown argument: -u
collect2.exe: error: ld returned 1 exit status

There were errors. (0:00.34)

I probably used it wrong. Can you explain me what's for ?

today I've got the same error, then just changed gcc compiler for MINGW v.9.3 (from msys) - & dll compiled OK (for Windows was compiled)... though I haven't load it yet in main() to use it...
but I agree with Mirek
mirek wrote on Thu, 12 February 2015 15:30
With .dll you have to sacrifice performance and do many things in more complicated way...



Best regards.

[Updated on: Tue, 05 January 2021 17:20]

Report message to a moderator

Re: Strange Architecture [message #55944 is a reply to message #55943] Tue, 05 January 2021 17:08 Go to previous message
JeyCi is currently offline  JeyCi
Messages: 50
Registered: July 2020
Member
del

Best regards.

[Updated on: Tue, 05 January 2021 17:19]

Report message to a moderator

Previous Topic: IGAL encrypted folder
Next Topic: About WebAssembly
Goto Forum:
  


Current Time: Tue Mar 19 09:02:11 CET 2024

Total time taken to generate the page: 0.01491 seconds