issue-#104 calling URLs and commands (InfoCmds capabilities)

Merged to the master branch
Ivan Denisov
Posts: 1700
Joined: Tue Sep 17, 2013 12:21 am
Location: Russia

Re: issue-#104 calling URLs and commands (InfoCmds capabilit

Post by Ivan Denisov »

Josef Templ wrote:But with every such generalization the API gets more complicated and eventually there is the question if
calling WinApi directly is actually simpler and more powerful.
Josef, I agree that in extra cases WinApi can be called directly.

I am sure that now we do not need to add errors handling. Many components using InfoCmds and it does not have errors handling. Now we need just replace it's functionality best and embedded way.

Extra threads solution is more appropriate because any called program will not touch normal BlackBox execution flow.
Actions was solving just a part of delay until persistent commands will finish, then BlackBox anyway would hang up. With threads now this will not happen.
Ivan Denisov
Posts: 1700
Joined: Tue Sep 17, 2013 12:21 am
Location: Russia

Re: issue-#104 calling URLs and commands (InfoCmds capabilit

Post by Ivan Denisov »

I think that for beta version this feature can be adopted already. We need this for issue-#100 to make links in About dialog.

Now is important to agree about the interface of Dialog.Run and Dialog.Open. The realization can be changed in beta or RC stages if somebody will detect any bugs.
Zinn
Posts: 476
Joined: Tue Mar 25, 2014 5:56 pm
Location: Frankfurt am Main
Contact:

Re: issue-#104 calling URLs and commands (InfoCmds capabilit

Post by Zinn »

Ivan, I'm agree with the interface definition.
Currently I do some tests with the different implementation and have not decided which one to use.
I compare the differnt behaivor between Windows and Wine.
My main problem is the cmd and the drive letters inside filename.
- Helmut
User avatar
Robert
Posts: 1024
Joined: Sat Sep 28, 2013 11:04 am
Location: Edinburgh, Scotland

Re: issue-#104 calling URLs and commands (InfoCmds capabilit

Post by Robert »

I have voted to abstain for now because:

1) - I would like to see the Docu text expanded, maybe with examples, to properly understand what these two do, and the differences between them

2) - I can't really comment much on the implementation as I have very little knowledge of the WinApi functions, but I don't like the static declaration of a 5 kByte string - I hate wasting memory!. Can it be much shorter, or dynamic so only used when required?

3) - Personally I would like the Run command to have an input Boolean option to open the "Dos Box" to see the .exe's output

4) - Can you explain how the "hook realisation" helps with error reporting. Surely that would have interface issues to get the information out?
User avatar
Josef Templ
Posts: 2047
Joined: Tue Sep 17, 2013 6:50 am

Re: issue-#104 calling URLs and commands (InfoCmds capabilit

Post by Josef Templ »

It not only wastes 5K Bytes but 10K Bytes because 1 CHAR needs 2 Bytes.
This must be cleaned up.
Ivan please look into the implementation.

- Josef
User avatar
Josef Templ
Posts: 2047
Joined: Tue Sep 17, 2013 6:50 am

Re: issue-#104 calling URLs and commands (InfoCmds capabilit

Post by Josef Templ »

More questions regarding the coding:

1. What is the parameter named "main" intended for?
Seems to be unused.

2. Are all windows resources released after a call to Open or Run?
It seems to me that the thread object survives. This would result in
running out of threads or thread handles when done repeatedly.

3. A parallel running thread must be restricted to use only very primitive stuff.
In particular it is not allowed to call arbitrary BB procedures or to
make use of the runtime system. But exactly this happens
when calling Dialog.IsWine() in a thread.

Folks, we must be careful with tricky low-level code changes like this one.
This issue may not yet be ready for voting.

- Josef
Ivan Denisov
Posts: 1700
Joined: Tue Sep 17, 2013 12:21 am
Location: Russia

Re: issue-#104 calling URLs and commands (InfoCmds capabilit

Post by Ivan Denisov »

This implementation with untagged arrays is used in i21sysCalls. And the size 5000 is chosen experimentally I guess from some practice.

You can run this simple test and see in the status bar and in system monitor of OS that calling to functions like that will not lead to memory leaks.

Code: Select all

MODULE ToolsLeakTest;
	IMPORT Dialog, Services, SYSTEM;
	TYPE A = POINTER TO RECORD (Services.Action) END;

	PROCEDURE Test;
	VAR
		t: ARRAY[untagged] 100000 OF REAL; i: INTEGER;
	BEGIN
		FOR i := 0 TO 99999 DO t[i] := Services.Ticks() END
	END Test;

	PROCEDURE (a: A) Do;
	BEGIN Test; Services.DoLater(a, Services.Ticks() + 100)
	END Do;
	
	PROCEDURE Start*;
	VAR a: A;
	BEGIN NEW(a); Services.DoLater(a, Services.now)
	END Start;

END ToolsLeakTest.
Ivan Denisov
Posts: 1700
Joined: Tue Sep 17, 2013 12:21 am
Location: Russia

Re: issue-#104 calling URLs and commands (InfoCmds capabilit

Post by Ivan Denisov »

Robert wrote:I would like to see the Docu text expanded, maybe with examples, to properly understand what these two do, and the differences between them
There is Docu.
PROCEDURE Run (IN exeName: ARRAY OF CHAR)
Run any external application. exeName can include path.

PROCEDURE Open (IN fileName: ARRAY OF CHAR)
Open fileName in external application associated with such file type.
URLs will be opened in default browser application.
If you want to add something, please suggest your text. From my point of view, we should not include any examples in this documentation.
Robert wrote:I can't really comment much on the implementation as I have very little knowledge of the WinApi functions, but I don't like the static declaration of a 5 kByte string - I hate wasting memory!. Can it be much shorter, or dynamic so only used when required?
It is allocated only ones for Dialog. Better not to make this string dynamic, because in this case garbage collector can clean it before other thread will use it. The size is used by the developers of i21sysCmds... However we can change it to 8191. This will be reasonable according this documentation:
https://support.microsoft.com/en-us/kb/830473 wrote:On computers running Microsoft Windows XP or later, the maximum length of the string that you can use at the command prompt is 8191 characters. On computers running Microsoft Windows 2000 or Windows NT 4.0, the maximum length of the string that you can use at the command prompt is 2047 characters.
Robert wrote:Personally I would like the Run command to have an input Boolean option to open the "Dos Box" to see the .exe's output
You can easily add your realization and even change them "on the fly" using procedure Dialog.SetExtCallHook(); I gave an example here.
Robert wrote:Can you explain how the "hook realisation" helps with error reporting. Surely that would have interface issues to get the information out?
For error reporting you can also make modified realization which will put reports in the log window during development. Later for production version normal HostDialog.Open/Run can be used. Or you can keep your realization with reporting if it necessary for target user.
Ivan Denisov
Posts: 1700
Joined: Tue Sep 17, 2013 12:21 am
Location: Russia

Re: issue-#104 calling URLs and commands (InfoCmds capabilit

Post by Ivan Denisov »

Josef Templ wrote:1. What is the parameter named "main" intended for?
Seems to be unused.
It is used to obtain handler of current thread. It is _Out_ parameter of WinApi.DuplicateHandle:
https://msdn.microsoft.com/ru-ru/library/windows/desktop/ms724251%28v=vs.85%29.aspx wrote:BOOL WINAPI DuplicateHandle(
_In_ HANDLE hSourceProcessHandle,
_In_ HANDLE hSourceHandle,
_In_ HANDLE hTargetProcessHandle,
_Out_ LPHANDLE lpTargetHandle,
_In_ DWORD dwDesiredAccess,
_In_ BOOL bInheritHandle,
_In_ DWORD dwOptions
);
Josef Templ wrote:2. Are all windows resources released after a call to Open or Run?
It seems to me that the thread object survives. This would result in
running out of threads or thread handles when done repeatedly.
This is good question. I think, that you are right and we can put WinApi.ExitThread(0) in appropriate positions. How did you see that the threads are alive?
Josef Templ wrote:3. A parallel running thread must be restricted to use only very primitive stuff.
In particular it is not allowed to call arbitrary BB procedures or to
make use of the runtime system. But exactly this happens
when calling Dialog.IsWine() in a thread.
I do not see any problems with calling Dialog.IsWine(). Even if somebody will remove the hook execution will not fall.
Josef Templ wrote:Folks, we must be careful with tricky low-level code changes like this one.
This issue may not yet be ready for voting.
We should do some movement to beta version, so I am suggesting to finish two pending features ASAP and then polish them in Beta and RC versions. If there is no objections about the interface, I ask you not to be so strict now and have to try to catch any low level bug in the beta stage.

We need this feature to make links from BB to Internet, so I can not finish Docu issue-#100 without it.
User avatar
Josef Templ
Posts: 2047
Joined: Tue Sep 17, 2013 6:50 am

Re: issue-#104 calling URLs and commands (InfoCmds capabilit

Post by Josef Templ »

Dialog.IsWine() cannot be called in a parallel thread.
Even if its current implementation happens to work (by accident)
this is way too dangerous.
If somebody changes it later then the parallel thread execution may
CRASH BlackBox completely. It should be clear to anybody that this
cannot go into master. It needs to be reconsidered in more detail first.

In general, it does not give sense to sacrifice the stability of the system
for a rarely used feature.

- Josef
Post Reply