Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Calling AVPageViewGoTo from another thread

Guest
Jul 26, 2017 Jul 26, 2017

Hello,

I would like to synchronize external events (from a WebSocket) and the advancement of my presentation in Acrobat.

I'd like to use the AVPageViewGoTo function when I get an event from this WebSocket.

Therefore, I created a C++ class  handling my WebSocket connection. In this class, I have a method binding the WebSocket's events to a function passed as a parameter.

In my plugin, I have a function ("GoToPage") which looks like this:

void GoToPage(int pageNumber)

{

AVPageView page = AVDocGetPageView(AVAppGetActiveDoc());

AVPageViewGoTo(page,pageNumber - 1);

}

I pass it as a parameter (as a std::function<void(int)>) to my WebSocket client.

My problem is that whenever the "AVPageViewGoTo(page,pageNumber - 1);" line is called from the client, my plugin crashes and I have an access read violation (even if page is not null).

I guess that this problem is due to the fact that I try to call a function of Adobe Acrobat's API outside the main thread (as explained here https://forums.adobe.com/thread/1432181). Is this correct?

If that is the case, can I create a handler as explained in the documentation to achieve my initial goal? And if so, may I get a bit more information on the topic?

Thanks in advance for your answers.

TOPICS
Acrobat SDK and JavaScript
856
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jul 26, 2017 Jul 26, 2017

No, you can't do anything like that. As noted, there are no Acrobat API features to help you with that. You have to have an event triggered BY ACROBAT in the main thread. The easiest way to do that is to register an idle proc to be called at intervals. The event has to somehow notice that it is expected to do work, and receive data (probably by looking in a synchronized thread-safe queue), and act on the requirement.

Translate
Community Expert ,
Jul 26, 2017 Jul 26, 2017

You are correct, all Acrobat API functions have to be called from the main thread. If you create other threads that need to communicate with the Acrobat API, you need to create an inter-thread communication channel that sends messages back and forth between the main thread and e.g. your second thread. This is nothing specific to Acrobat, anything that is supported in the operating system you are working on to communicate between threads will work. Just google for "inter thread communication", and you should find enough information to help you implement such a communications channel.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 26, 2017 Jul 26, 2017

You must make all calls from the main thread. More than that, you must make them when Acribat expects them. Plugins run synchronously when Acrobat sends them events. Only then can you use the API.

The simplest event, though not the most efficient, is an idle callback.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 26, 2017 Jul 26, 2017

I'm not sure I understood what you meant. Do you mean that instead of passing GoToPage as a parameter, I should pass a function creating a callback. Something like this ?

void CreateProtoGoToPage(int pageNumber)

{

ASCallbackCreateProto(AVExecuteProc, GoToPage);

}

If so, how can I pass pageNumber as a parameter to GoToPage? Will GoToPage be then executed?

If I understood correctly, ASCallbackCreateProto only creates the callback, it doesn't execute it.

A few more explanations would greatly help .

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 26, 2017 Jul 26, 2017

No, you can't do anything like that. As noted, there are no Acrobat API features to help you with that. You have to have an event triggered BY ACROBAT in the main thread. The easiest way to do that is to register an idle proc to be called at intervals. The event has to somehow notice that it is expected to do work, and receive data (probably by looking in a synchronized thread-safe queue), and act on the requirement.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 28, 2017 Jul 28, 2017

Ok, thank you very much.

Do you, by any chance, have resources about this idle process registration?

I have never done that before, and my research only led me to this (https://msdn.microsoft.com/en-us/library/3dy7kd92.aspx​), which would force me to make this functionality of my plugin platform-dependent. Moreover I don't have any concrete idea about where to do such thing in my plugin.

I know how I could create a thread from the plugin (which obviously doesn't solve the problem since I would still call GoToPage from another thread), but not what I could do so that the actual main thread periodically checks the current page.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 28, 2017 Jul 28, 2017

That is an API feature. AVAppRegisterIdleProc.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 28, 2017 Jul 28, 2017
LATEST

Indeed, everything works now. Thanks for your time!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines