From: Frans S. <fra...@gm...> - 2010-03-04 13:31:36
|
Hi Francesco, On Thu, 2010-03-04 at 10:44 +0100, Francesco wrote: > Hi Frans, > > 2010/3/4 Frans Schreuder <fra...@gm...>: > > I saw that in your modifications, you called libusb_init() from > main.cpp (as > > well ass libusb_exit). > > I think it is better to move this to the hardware constructor and > > destructor. > hmmm, why? Because the way it was, only the gui part was connecting to the programmer, when the command line interface was invoked, usbpicprog gave a seg fault. Of course it is also possible to initialize libusb twice, but I think from hardware is more charming... > > > I already tested this in linux, but I don't know if it works out > > well on all systems? > on Windows it didn't work well with the earlier versions of the libusb > windows port. I didn't test recently but in any case I think that the > initialization is a bit slow because the windows port needs to > internally enumerate the USB hubs AFAIR. > > > What was the reason for you to call these functions from main? > in general the initialization of all libraries is done in the main() > of a program and never repeated (as it shouldn't really be > necessary!). The initialization routines usually allocate memory and > perform many operations which maybe time-consuming. I don't think we > should repeat them multiple times unless absolutely necessary. > > In fact, I think that also the current organization of the Hardware > class, which gets allocated and deleted multiple times should also be > avoided: upp_wx currently is very slow to start up and IIRC this is > because Hardware is created and deleted 2-3 times at the startup. > I'd really like much more to have a > Hardware m_hw; > member in UsbPicProg class definition and then have just a > bool Connect(HardwareType hwToTryToConnect); > member in the Hardware class which would be used by UppMainWindow > (only when necessary). > > I think this would be: > 1) a better design from a OOP point of view. > 2) more efficient design => reduce startup time of upp_wx. That's ok, in that case we can still init libusb from hardware, but only init hardware once. > > If you agree I can do such modifications in the weekend... I will do it myself, but I think it's a good idea. Frans |