Demand load vs explicit arxload ...

Started by MP, June 23, 2007, 08:53:37 AM

Previous topic - Next topic

MP

I understand the benefit of providing demand loading to general consumers of OpenDCL but what's the benefit of calling (command "opendcl")  or (vl-cmdf "opendcl") from a loader program, e.g. (_Load_ODCL_Runtimes) rather than explicilty loading the arx file?

In other words, is it being invoked merely because it's available or because it's better than explicit loading?

To illuminate, is this --

(defun _Load_ODCL_Runtimes ( )

    ;;  If ObjectDCL is already loaded return T, otherwise
    ;;  attempt to load (return T on successful load, else
    ;;  print an appropriate message; return nil).

    (or

        ;;  Already loaded, no need to do anything else.

        dcl_getversionex

        ;;  Attempt to demand-load the runtimes.

        (if (< 1 (getvar "demandload"))
            (   (lambda ( / cmdecho )
                    (setq cmdecho (getvar "cmdecho"))
                    (setvar "cmdecho" 0)
                    (vl-catch-all-apply 'vl-cmdf '("opendcl"))
                    (setvar "cmdecho" cmdecho)
                    dcl_getversionex
                )
            )
        )

        ;;  Still not loaded, attempt to load the runtimes explicitly.

        (   (lambda ( / proc_arch arxname arxpath )

                ;;  Determine the appropriate arx module for
                ;;  the processor and the AutoCAD version.

                (setq arxname
                    (strcat "OpenDCL"
                        (if
                            (and
                                (setq proc_arch
                                    (getenv "PROCESSOR_ARCHITECTURE")
                                )
                                (< 1 (strlen proc_arch))
                                (eq "64"
                                    (substr
                                        proc_arch
                                        (1- (strlen proc_arch))
                                    )
                                )
                            )
                            ".x64."
                            "."
                        )
                        (substr (getvar "acadver") 1 2)
                        ".arx"
                    )
                )

                ;;  What was the result?

                (cond
                    (   (null (setq arxpath (findfile arxname)))
                        (princ (strcat "Couldn't find " arxname ".\n"))
                        nil
                    )
                    (   (null (arxload arxpath nil))
                        (princ (strcat "Failed to load " arxname ".\n"))
                        nil
                    )
                    (   t   ) ;; We're good.
                )
            )
        )
    )
)


Better than this --

(defun _Load_ODCL_Runtimes ( )

    ;;  If ObjectDCL is already loaded return T, otherwise
    ;;  attempt to load (return T on successful load, else
    ;;  print an appropriate message; return nil).

    (or

        ;;  Already loaded, no need to do anything else.

        dcl_getversionex

        ;;  Not loaded, attempt to load the runtimes explicitly.

        (   (lambda ( / proc_arch arxname arxpath )

                ;;  Determine the appropriate arx module for
                ;;  the processor and the AutoCAD version.

                (setq arxname
                    (strcat "OpenDCL"
                        (if
                            (and
                                (setq proc_arch
                                    (getenv "PROCESSOR_ARCHITECTURE")
                                )
                                (< 1 (strlen proc_arch))
                                (eq "64"
                                    (substr
                                        proc_arch
                                        (1- (strlen proc_arch))
                                    )
                                )
                            )
                            ".x64."
                            "."
                        )
                        (substr (getvar "acadver") 1 2)
                        ".arx"
                    )
                )

                ;;  What was the result?

                (cond
                    (   (null (setq arxpath (findfile arxname)))
                        (princ (strcat "Couldn't find " arxname ".\n"))
                        nil
                    )
                    (   (null (arxload arxpath nil))
                        (princ (strcat "Failed to load " arxname ".\n"))
                        nil
                    )
                    (   t   ) ;; We're good.
                )
            )
        )
    )
)


?

Also, since demand loading may not be enabled one cannot omit the explicit loading anyway, so I'm thinking I'll probably go the latter.

Thoughts?

Thanks!

Michael.

:)
The thing about life is that it takes up all your time (wifey).

MP

The thing about life is that it takes up all your time (wifey).

Kerry

Quote from: MP on June 24, 2007, 07:11:06 AM
Should I nuke this post?

Perhaps just add a note when you decide which way to handle it Michael.

For viewers: There is an ongoing discussion at SourceForge about this topic.
Perfection is not optional.
My other home is TheSwamp

MP

Thanks Kerry.

I've pretty much finalized my loader code; I'll post it tomorrow.

Should I --

(A) post here but keep mum about this site (I have so far)?
(B) Post here and make brief post on SF pointing back here?
(C) Teach a fish how to ride a bicycle?

;D
The thing about life is that it takes up all your time (wifey).

BazzaCAD

You guys can go ahead & keep posting here so we can test out the forum, but the main discussions should still be at SF.
And ya keep it quite for awhile. I want to have the main site up & running before things go public & hopefully at the same time as when OpenDCL goes public...
a.k.a.
Barry Ralphs
barryDOTralphsATgmailDOTcom

MP

The thing about life is that it takes up all your time (wifey).

MP

I'm posting here because there's no other proper place to review source code snips like this and doing it by email is not very efficient in my estimation.

Slay away --

    (defun _Load_ODCL_Runtime ( / loaderp proc_arch arxname arxpath errmsg )
   
        ;;  Let's be clear on the intent of the loader. When Joe User
        ;;  loads up the parent application there is full intent to
        ;;  run it, regardless whatever the demand load setting may be.
        ;;  Speaking frankly if I may, the majority of users don't know
        ;;  diddly about demand loading and I don't believe it's the
        ;;  responsibility of this loader to edumacate 'em.
        ;;
        ;;  What Joe thinks he knows when the application he intended to
        ;;  run fails (because demand loading is disabled) is that it is
        ;;  somehow broken (despite any lucid explainations about demand
        ;;  loading that migh be provided) - "Yeah, I saw some cryptic
        ;;  message about demand something or other ... maybe they will
        ;;  fix that in the next version".
        ;;
        ;;  Further, at our camp we want the applications to run. Period.
        ;;  I acknowledge that this perspective won't necessarilly be
        ;;  shared universally, but I'm making the attempt to explain my
        ;;  rationale for what follows.
        ;;
        ;;  Finally, if someone actually knows what they're doing and re-
        ;;  quires a clean environment (one possible intent for disabling
        ;;  demand loading) they'll know how to dump the OpenDCL runtime
        ;;  via arxunload.
        ;;
        ;;  With the above as a context this function is hereby designed.
        ;;
        ;;  The loading attempt order (if not already loaded):
        ;;
        ;;  1.  If OpenDCL has been installed on this machine via the
        ;;      installer use the path to the runtime as specified in
        ;;      the registry for demand loading -- but load via arxload
        ;;      regardles the demand load setting.
        ;;
        ;;  2.  If the OpenDCL runtime is found in the support path use
        ;;      arxload to load said runtime.
        ;;
        ;;  3.  If OpenDCL has been installed on this machine via the
        ;;      installer *AND* demand loading is enabled force the load-
        ;;      ing of the runtime via invoking the OpenDCL command.
        ;;
        ;;  Verbosely / gratuitously annotated for noobs and bit weiners
        ;;  alike.

        (or

            ;;  Already loaded, vacate now (return t to caller).

            dcl_getversionex
           
            ;;  SECTION 1. Attempt to load the runtime via arxload using
            ;;  the path associated with the opendcl demand loader (the
            ;;  intent: Use said path but do not use the OpenDCL command
            ;;  to induce loading the arx). In other words don't use
            ;;  command / vl-cmdf.
           
            (and
           
                ;;  Is demand loading is specified for OpenDCL?
           
                (setq arxpath
                    (vl-registry-read
                        (strcat
                            "HKEY_LOCAL_MACHINE\\"
                            (vlax-product-key)
                            "\\Applications\\OpenDCL"
                        )
                        "Loader"
                    )               
                )
               
                ;;  We'll use the following variable in SECTION 3.
               
                (setq loaderp t)
               
                ;;  Is she an arx file?
               
                (wcmatch (strcase arxpath) "*`.ARX")         
               
                ;;  Was the load attempt successful?
               
                (arxload arxpath nil)
               
                ;;  Is core OpenDCL functionality now defined?
               
                dcl_getversionex
            )                   

            ;;  SECTION 2. Attempt to arxload the runtime explicitly by
            ;;  finding it in the support path.
           
            (and

                ;;  Determine the appropriate arx module for the pro-
                ;;  cessor and the AutoCAD version.

                (setq arxname
                    (strcat "OpenDCL"
                        (if
                            (and
                                (setq proc_arch
                                    (getenv "PROCESSOR_ARCHITECTURE")
                                )
                                (< 1 (strlen proc_arch))
                                (eq "64"
                                    (substr
                                        proc_arch
                                        (1- (strlen proc_arch))
                                    )
                                )
                            )
                            ".x64."
                            "."
                        )
                        (substr (getvar "acadver") 1 2)
                        ".arx"
                    )
                )
               
                ;;  Is the arxfile in the support path somewhere?
               
                (setq arxpath (findfile arxname))
               
                ;;  Was the load attempt successful?               
               
                (arxload arxpath nil)
               
                ;;  Is core OpenDCL functionality now defined?
               
                dcl_getversionex               
            )
           
            ;;  SECTION 3. If demand loading is enabled use the OpenDCL
            ;;  command to induce the loading of the OpenDCL runtime.
            ;;  If we got here it possibly means the runtime is no lon-
            ;;  ger an arx file (maybe an exe) or the arxload attempt in
            ;;  SECTION 1 failed for some reason. Regardless, it appears
            ;;  a demand loader is still present, so let's try to use it
            ;;  to load the OpenDCL runtime.

            (and
               
                ;;  The following variable 'loaderp' is initialized from
                ;;  the first attempt to load the runtime in SECTION 1.
                ;;  If null it means no OpenDCL loader is present on this
                ;;  machine so there's no point in invoking the OpenDCL
                ;;  command.
               
                loaderp

                ;;  A loader is defined but let's ensure demand loading
                ;;  is enabled, lest the invocation of the OpenDCL com-
                ;;  mand be pointless.

                (< 1 (getvar "demandload"))
               
                ;;  We're good, invoke the OpenDCL command ...
                                               
                (vl-catch-all-apply 'vl-cmdf '("opendcl"))
               
                ;;  Is core OpenDCL functionality now defined?
               
                dcl_getversionex
            )
           
            ;;  If we got here the opendcl runtime was not loaded.

            (progn
           
                ;;  Inform the user of the sad news.
           
                (princ
                    (strcat
                        "Error: "
                        (if arxpath
                            (strcat arxpath " <failed to load>")
                            "OpenDCL runtime <not found>"
                        )
                        ".\n"
                    )
                )
               
                nil
            )
        )
       
        dcl_getversion

    )
The thing about life is that it takes up all your time (wifey).

BazzaCAD

Looks good. I think I'll use this for the "ManualLoading.lsp" example, without your initial commands. ;-)
Unless anyone else objects...
a.k.a.
Barry Ralphs
barryDOTralphsATgmailDOTcom

MP

Quote from: BazzaCAD on June 25, 2007, 11:20:15 AM
Looks good. I think I'll use this for the "ManualLoading.lsp" example, without your initial commands. ;-)
Unless anyone else objects...

If you meant "comments" I agree - they were provided to stimulate discussion amonsgt you folks, not for public consumption.

I'd wait to including it as is unril some feedback comes in -- while it's perfect for my needs I can't comment on it's general useability / applicability.

But thanks for the implied vote of confidence (if it's ok to infer that).

:)
The thing about life is that it takes up all your time (wifey).

Kerry


Michael, How are you proposing implementing this. ?

ie, where and how will the loader be loaded , and how and how often will it be called.

I'm currently demand loading from my MNL file without fault. I imagine your loader could be run in-line (or  called) from an MNL in a similar manner ... eliminating the need for any further checking.

Perfection is not optional.
My other home is TheSwamp

MP

It's a good question Kerry, my apologies for failing to put the snip into some perspective (and for the delay responding).

Basically it is an excerpt from the two dist samples I penned and I was looking for feedback and / or a sanity check. I didn't think it was mature enough to suggest it as a global loader per se, though in my own coding I will be using a library / toolbox approach, as defining said code repeatedly doesn't make much sense.

Thanks,

Michael.
The thing about life is that it takes up all your time (wifey).

Kerry

Quote from: MP on June 27, 2007, 03:26:08 PM
...........   though in my own coding I will be using a library / toolbox approach, as defining said code repeatedly doesn't make much sense.
.............Michael.

I Concur.

I imagine that most people wiil aim in the same direction after they become comfortable with the Odcl tools.
Perfection is not optional.
My other home is TheSwamp