Skip to main content

Notice

If you are using a Hotmail or Outlook email address, please change it now, as Microsoft is rejecting all email from our service outright.
Topic: fb2k API questions (Read 5814 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

fb2k API questions

@Peter , could you help with the following, please?

1. playlist_manager_v4::create_playlist_ex / playlist_manager_v4::create_playlist_ex: in which case can it return pfc_infinite? Is it more like paranoia check (i.e. assert would suffice) or should I always validate it?
2. What is assigned to the return value of playlist_manager::playlist_insert_items? Is it the new position of the first track (i.e. same as p_base argument)?
3. Is there any difference between using u* methods from shared.dll and using corresponding WinAPI methods? E.g. uCreateFile vs CreateFile

Thanks in advance =)

Re: fb2k API questions

Reply #1
1.
Playlist creation will fail if called from an illegal context - wrong thread, called from a global callback, fb2k shutdown in progress.
If your code already ensures running in main thread, an assert check should be sufficient.
You cannot call any methods that alter the state of playback, playlist, etc from a global callback - such as playlist/playback/etc callback - because the method by itself dispatches callbacks, which cannot be done recursively.
2.
Returned value from playlist_insert_items is the index of the first inserted track - or pfc_infinite on failure (conditions above or an autoplaylist that refuses insertions).
3.
u* methods used to be relevant when Win9X was still supported - Win9X users got a different build of the DLL which called non-Unicode APIs. By now there's no difference. These methods are mainly retained for backwards compatibility. Though you can sometimes reduce the size of your component by calling them instead of converting UTF-8 to wchar_t by yourself.

Re: fb2k API questions

Reply #2
Thanks!

1.
Playlist creation will fail if called from an illegal context - ... fb2k shutdown in progress ...
Am I right to assume that this condition won't be triggered until after initquit::on_quit callback is executed?

And another small question:
Can autoplaylist_manager::add_client_simple(p_query, p_sort, p_playlist, p_flags) fail on a newly created playlist?

Re: fb2k API questions

Reply #3
If your component creates playlist in direct response to user events, it is safe to assume that shutdown is not yet in progress.
initquit::on_quit() is one way to know about shutdown in progress, but if some other component decides to do stuff that triggers your code in their on_quit(), your on_quit() might not yet have executed.

autoplaylist_manager::add_client_simple() on a newly created playlist should never fail. The current implementation throws an exception if the specified playlist index is invalid, or if the playlist is already an autoplaylist, neither of which can be true in your case.



Re: fb2k API questions

Reply #6
If anyone stumbles on the question above: judging by disassembly, it seems that modal_dialog_scope::can_create() always returns false when invoked on non-main thread.

Re: fb2k API questions

Reply #7
Everything modal dialog related should only ever be called from main thread.

modal_dialog_scope::can_create() returns false when either called from a non main thread or there already is a known modal dialog running.


Re: fb2k API questions

Reply #9
@Peter, another small API question =)
What's the purpose of modal_dialog_scope? Is it purely a FYI method (i.e. indication that it would be possible to create a modal dialog)? Is it safe to invoke a modal dialog without wrapping it's call in modal_dialog_scope?

Re: fb2k API questions

Reply #10
And another question: what is the correct way for a component to generate a dynamic main menu (i.e. so that it could be changed after component initialization)? There is such menu for playlists ('View>Switch to playlist'), but I'm not sure how to achieve that....

I've found 'mainmenu_commands_v2' which might be what I need: there is a `mainmenu_commands_v2::dynamic_execute` method which accepts subId GUID, but should this GUID be distinct from all the other menu GUIDs? If so, then should I run a check against already defined GUIDs every time I add a new menu item?

Re: fb2k API questions

Reply #11
modal_dialog_scope exists to prevent accidental creation of another modal dialog while a modal dialog is already in progress. Execution of various fb2k menu commands is not blocked during a modal dialog, but you can at least know that there's a modal dialog in progress and refuse to create another one - which could lead to modal dialogs getting dismissed out of order or worse.

Dynamic mainmenu commands will be added to foo_sample.

Re: fb2k API questions

Reply #12
Thanks for the answers!

modal_dialog_scope exists to prevent accidental creation of another modal dialog while a modal dialog is already in progress. Execution of various fb2k menu commands is not blocked during a modal dialog, but you can at least know that there's a modal dialog in progress and refuse to create another one - which could lead to modal dialogs getting dismissed out of order or worse.
Hm... So that means that it is actually *required* for the component to wrap every modal dialog creation call. I think it would be nice to add this to 'modal_dialog_scope' documentation =)

Dynamic mainmenu commands will be added to foo_sample.
Thanks!

Re: fb2k API questions

Reply #13
Aaaand another one:
Is it possible to disable `space` key handling by fb2k in DUI so that it could be passed (and handled) by panel? E.g. user wants to enter some text.

Re: fb2k API questions

Reply #14
@Peter: another question, if you don't mind =) What is the proper way to execute API action that requires initialized fb2k?

Example scenario #1: I want to show popup via `popup_message::g_show` during CUI panel creation (which happens before component's `on_init` is called). If invoked before fb2k is initialized, no popup will show up.

Example scenario #2: invocation timing is the same as above, but I need fb2k handle (via `core_api::get_main_window()`). This handle will be nullptr if requested before fb2k initialization.

Current workaround: queue all required action and execute them in the component's `on_init` callback.
Other workaround: queue actions via `fb2k::inMainThread` (this uses message queue probably, which activates only after fb2k initialization).

PS: The question above is still relevant =)

Re: fb2k API questions

Reply #15
@Peter, another small question (that's slightly similar to the one above):
Am I correct to assume that init_stage_callback::on_init_stage(init_stages::after_ui_init) will be called after *all* components have been initialized?

Re: fb2k API questions

Reply #16
Sounds like CUI panel creation occurs when there's no known main window yet. Apparently the popup_message code doesn't like that - does nothing instead of creating a parentless (toplevel) dialog.

initquit::on_init() gets called when everything's initialized, main window has been created and all other APIs are valid to call.
init_stage_callback::on_init_stage(init_stages::after_ui_init) gets called just before initquit::on_init().

In general, fb2k::inMainThread() should work for deferring problematic API calls.
Or, check if core_api::get_main_wiindow() returns null; if so, store the messages and show popups from initquit::on_init().

Not sure what you mean about space key handling, embedded Album List in Default UI can take space key in its editbox just fine?

Neat trick with the [font] for code bits, I'll have to remember that one

Re: fb2k API questions

Reply #17
Thanks for all the answer! Really appreciated!

Not sure what you mean about space key handling, embedded Album List in Default UI can take space key in its editbox just fine?
You are absolutely right: this is a bug/feature in my code... Sorry for the confusion >_<

Neat trick with the [font] for code bits, I'll have to remember that one
I was just too used to being able to inline `code blocks` in markdown. Thankfully, Google knew the answer =)

Re: fb2k API questions

Reply #18
@Peter, the problem is that initquit::on_init in one component might be called before the initquit::on_init in another component.
E.g. my component is already up (initquit::on_init was called) and tries to use another component, which is not yet loaded completely (have yet to handle initquit::on_init).
Is there a callback (or maybe a bool check, which would be harder to abuse by component devs) to verify that fb2k has loaded all components (invoked all initquit::on_init callbacks) and thus it's safe to call any component?

Re: fb2k API questions

Reply #19
@Peter, another day - another API question =)
Does API guarantee that input implemented with `input_factory_t` will not be called before `initquit::on_init` and after `innitquit::on_quit` (all implemented in the same component)?

Re: fb2k API questions

Reply #20
No guarantees about inputs being called before on_init() or after on_quit().
Better just init on first use (std::call_once) and never deinit - only make sure all worker threads exit before process exits.

Re: fb2k API questions

Reply #21
Thanks for the answer!
Another small question: is it possible to get the metadb of the next track? I mean not 'next track in playlist', but the actual track that will be played next. Scenario: pre-loading the next track (if needed) to avoid hiccups.

Re: fb2k API questions

Reply #22
Next track info is not currently available. Decision on what to play next (random etc) is made at the point decoding of the previous track has EOF'd, so the info doesn't physically exist until the track needs to start decoding.


Re: fb2k API questions

Reply #24
Aaaand another few small questions =)
1. Is it possible to create a custom auto-playlist, i.e. an auto-playlist that is managed by component?
Scenario: Spotify (a music streaming service) provides a playlist interface via an url. So ideally, a user could pass such link to the component, which would create an playlist that would be periodically synchronized with the Spotify service.

2. Is it possible to import multiple files via a single `File` > `Add location`? I.e. not as a single track with subsongs (`input_factory_t`), but as multiple separate tracks?
Scenario: same as above - an import of Spotify playlist.

Thanks in advance =)

 
SimplePortal 1.0.0 RC1 © 2008-2020