Archive for April, 2008

Library debug

Thursday, April 17th, 2008

When I worked on the PhotoFiltre Plugins Pack, I imported a library, the PureHTTP one, in order to download files from the Internet without using any API (this made work easier to port to Linux!). Problem was: that’s a library, that sometimes needs to debug stuff. It was using the classical way, I mean : Debug Var.l. In my case, that was really useless. Because that way, it uses the PureBasic debugger. A debugger that’s not included in final application. Moreover, the PhotoFiltre Plugins Pack has his own included debugger that can be launched with command line (-debug), that was that one I wanted to debug. First, I replaced all the appropriate calls by a PPPDebug(Str(Var)) (PPPDebug is the debug function of the PPP, it writes to stdout the strings it receive before it checked debug mode is activated). But doing that way, I was obliged to declare PPPDebug because libs are included before program functions. So, PureHTTP wasn’t a library any longer (it wasn’t independent because of the function used to debug).

I finally found a quite nice solution to get rid of this problem. I implemented a special debug function in the lib, and each debug call was done with that function. The concept of this function is easy to understand. If it’s called without any initialization, it just debug using the old way. Otherwise, it can be initialized to use a specific debug function (that can be outside the lib, of course!). in that case, it just calls the specified function with the string to debug. Let’s see the code:

#DEBUG_RESET = -1

; That’s the function that will be included in Library
; Each time a library function will have to debug something,
; it will have to call it that way LibraryDebug(”Something to debug”)
; The function can be initialized to use program debug function
; passing null string to Text.s and a pointer to the debug function
; In order to reset, just use the constant. When no debug function
; has been defined, it uses debugger.
; This system allows keeping a dependent library using program debugging systems
Procedure LibraryDebug(Text.s, Flag.l = 0)

  Static DebugFunction

  If Not Text And Flag ; We are defining Debug method
    If Flag = #DEBUG_RESET
      DebugFunction = 0
    Else
      DebugFunction = Flag
    EndIf
  Else ; We are debugging
    If DebugFunction
      CallFunctionFast(DebugFunction, Text.s) ; Use defined Debug method
    Else
      Debug “Default: “+Text.s ; Else use debugger
    EndIf
  EndIf

EndProcedure

The comments are (I think) explicit. To define the function to use, simply call LibraryDebug with null text, and in flag, the address of the function to call. When passing the constant defined upper, the function do a reset, next call will be done as if the function had not been initialized (that feature isn’t in the PureHTTP implementation for PPP, because I don’t need it…). Just a small example to see how it works (even if that’s not hard to understand ;)):

; One way to debug, using console
Procedure DebugConsole(Text.s)

  PrintN(”Console: “+Text.s)

EndProcedure

; One way to debug, using message boxes
Procedure DebugRequester(Text.s)

  MessageRequester(”Debug”, “Requester: “+Text.s)

EndProcedure

; On way to debug (the easiest), using PB debugger (if activated)
Procedure DebugDebug(Text.s)

  Debug “Debug: “+Text.s

EndProcedure

; Sample code :) !
OpenConsole()
LibraryDebug(”Something to debug”)
LibraryDebug(”", @DebugConsole())
LibraryDebug(”Something to debug”)
LibraryDebug(”", @DebugRequester())
LibraryDebug(”Something to debug”)
LibraryDebug(”", @DebugDebug())
LibraryDebug(”Something to debug”)
LibraryDebug(”", #DEBUG_RESET)
LibraryDebug(”Something to debug”)

; Wait until user press enter to quit
Input()

Just run it with, or without debugger.

It also exists an easier (a bit only) way to code LibraryDebug, using ASM to avoid the call to CallFunction (and so including the Library lib from PureBasic) whereas we have the function pointer. That way:

Procedure LibraryDebug(Text.s, Flag.l = 0)

  Static DebugFunction

  If Not Text And Flag ; We are defining Debug method
    If Flag = #DEBUG_RESET
      DebugFunction = 0
    Else
    DebugFunction = Flag
    EndIf
  Else ; We are debugging
    ! MOV ebx, dword [s_LibraryDebug.v_DebugFunction]
    ! TEST ebx, ebx
    ! JZ l_librarydebug_stddbg
    ! PUSH dword [p.v_Text]
    ! CALL ebx ; Use defined Debug method
    ! JMP l_librarydebug_end
    LibraryDebug_StdDbg:
    Debug Text.s ; Else use debugger
    LibraryDebug_End:
    ! XOR ebx, ebx
  EndIf

EndProcedure

PhotoFiltre Plugins Pack 1.5

Sunday, April 13th, 2008

Before I start with that topic, some reminding. The PhotoFiltre Plugins Pack (also called PPP or internally 3P) is an application which was first an InnoSetup script to install the PhotoFiltre plugins easily (without any manual unzip, etc.). However this first version was really limited in functionnalities: it was really long to download (more than 10MB), was never up to date, wasn’t enough easy for users (they didn’t know where to install the plugins, etc.). So, I started working on a real application dedicated for the installation, and which was always up to date: the new PPP was born. The concept is quite simple: the plugins page is downloaded from the PhotoFiltre site, then parsed and finally a plugins list is generated. The user has just to choose the plugins to install. Then, he selects where he wants to install them, but in easier way (than the first PPP), it helps avoiding any error and making the step easier. Finally, the selected plugins are downloaded and installed (ie: extracted in the right place), and the PhotoFiltre (and/or Studio) configuration is updated to enable the plugins support. It’s the skeleton of the PPP. There are some other features, and some came later (such as the configuration modification, the Windows Vista support).

What will the new PPP release (1.5) bring?
From the user side, well… nearly nothing! The new release will just be safer, more stable, and a bit faster. It will also display more informations while accessing the Internet and while installing the plugins. From an other side (not really well defined… :D), this release will be a great revolution (which doesn’t work very well for now, but I keep hoping) which aims to port the PPP 1.5 to Linux for the users who use PhotoFiltre under Wine. For now, the Linux port doesn’t work for a weird reason (and also because a large part of the code is missing) but if you’re interested about the functional stuff, some screenshots are available on the Internet (on the PhotoFiltre boards :)). The Linux release will be the same than the Windows one. So, it means that many (really many) Windows API calls have been removed (and some GTK+ API calls are used now :p). But, it especially means that I needed to reorganize the whole source code, in order to have an easy code to maintain under the both OSes. And that’s because of this work that the PPP while have the major evolution it ever had (in my opinion, of course!): the source code will be released under a free licence (I still don’t know which one). The PPP will become an open-source software (one more!). I’ve to goals when doing that: first one, I hope someone would be able to improve the PPP if I stopped to develop it (for X or Y reasons, who knows?). The second one is “better” (for coders), the PPP is now a mature and important program that could help people who code in PureBasic (coding language used for the PPP). They will perhaps be able to learn some tricks. 

PhotoFiltre Plugins Pack 1.5 Linux     PhotoFiltre Plugins Pack 1.5 Linux     PhotoFiltre Plugins Pack 1.5 Windows
Some pictures of the PPP 1.5 when developed

Well… There’s nearly nothing more to add, the two big announce have been written. I hope this will enjoy some people to read about the future of the PPP.

Have a nice day!

First Post

Sunday, April 13th, 2008

Hi!

I finally made it: creating a blog. I didn’t really know what I could put in, and I still don’t know. But that doesn’t matter. I’ll found (I hope!) some interesting subject to expose. I think the use of this blog will lead to the death of the previous one. The one I did for my hosting server (the new blog is hosted there ;)) to keep people in touch with the news things (or the problems…). But I didn’t fill it with server topics, I just spoke about programming (when I remembered I had a blog :)). Moreover, the previous blog is sinking under tones of spam. What a good reason to start a new blog! One other reason could be: all the developers I know have a blog where they expose the results of their work, and I find that’s a great idea.

But (and that’s the most important question, I think) why is this blog in English? Not because I became completely crazy or pretentious, but because my aim is to make this blog (and its contents) a bit international. Also because, as I’m a member of the ReactOS Development Team, I’d like to let the other developers read my pieces of reflection.

Well… That’s all (and enough) for this post. The next one will (probably) be a translated post from my previous blog about the PhotoFiltre Plugins Pack. Do not to express yourself to let me know what you like and dislike about this blog (and the rest…).