[GNC-dev] Can a module call a function from another module?
John Ralls
jralls at ceridwen.us
Sat Apr 18 15:02:18 EDT 2020
One other consideration: The dependency should make sense architecturally: A dependency on code in libgnucash/engine nearly always makes sense; a dependency in the register on a function in import/export does not. That doesn't mean that you should copy-and-paste the code instead, it means that the code should be extracted from import/export and moved somewhere that does make sense. The logical place for GUI code is gnome-utils while business logic code belongs in libgnucash/engine--and note that there is a *lot* of business logic code that has gotten intermingled with GUI code and needs to be refactored out. It's a major maintenance headache because it often means that the same business logic is implemented in more than one place, often with subtle differences.
Whether that's the case for your window-reconcile.c example depends on what you need to do: If you want to launch the reconcile window from the OFX importer the way AQBanking does, no problem. If you need some implementation function in window-reconcile.c then it strongly suggests that that function is of more general use than just the reconcile window and probably belongs somewhere else.
Regards,
John Ralls
> On Apr 18, 2020, at 5:29 AM, Geert Janssens <geert.gnucash at kobaltwit.be> wrote:
>
> First off, modules are mostly on the way out. I have been working on removing most uses of
> those and plan to eliminate even more. The gnc_module code itself will remain until we have a
> better alternative.
>
> Other than that, yes, you are allowed to include headers from other "modules". Or more
> generally from other compile units (the objects defined with add_library or add_object). There
> are other restrictions though:
>
> 1. you may have to add the proper include and library directories to the compile unit's
> CMakeLists.txt file. Without this the compiler won't find the header file (and later the library to
> link to)
>
> 2. In doing so you should be careful not to introduce circular dependencies. That is if unit A
> already depends on unit B, you can't make unit B also depend unit A.
>
> 3. reconcile-window.h is a C header file, while gnc-ofx-import.cpp is a C++ source file. You may
> have to include it inside an 'extern "C"' block.
>
> You didn't provide any details as to what errors you got, so at this point it's hard to tell what
> exactly went wrong.
>
> Regards,
>
> Geert
>
> Op zaterdag 18 april 2020 07:29:15 CEST schreef jeanl:
>> Devs, I have a question to which I can't find an answer. It is possible for
>> a function from a module (say import-ofx) to call a function from another
>> module (declared in "reconcile-window.h" for example).
>> I'm not able to include reconcile-window.h from gnc-ofx-import.cpp , I
>> assume the build isn't setup to include the right headers.
>> But perhaps this is by design and a module isn't supposed to be able to call
>> another one. In that case, how can we make it so a function from a certain
>> module is followed by a call to a function from a different module
>> automatically?
>> J.
>>
>>
>>
>> --
>> Sent from: http://gnucash.1415818.n4.nabble.com/GnuCash-Dev-f1435356.html
>> _______________________________________________
>> gnucash-devel mailing list
>> gnucash-devel at gnucash.org
>> https://lists.gnucash.org/mailman/listinfo/gnucash-devel
>
>
> _______________________________________________
> gnucash-devel mailing list
> gnucash-devel at gnucash.org
> https://lists.gnucash.org/mailman/listinfo/gnucash-devel
More information about the gnucash-devel
mailing list