updated to support watching of individual nodes.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@865 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
bb24170e40
commit
9f44244a66
@ -3,12 +3,99 @@
|
|||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <List.h>
|
||||||
#include <Invoker.h>
|
#include <Invoker.h>
|
||||||
#include <Alert.h>
|
#include <Alert.h>
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
#include <MediaRoster.h>
|
#include <MediaRoster.h>
|
||||||
|
|
||||||
BMediaRoster *roster;
|
BMediaRoster *roster;
|
||||||
|
BList watchlist;
|
||||||
|
bool globalwatch = true;
|
||||||
|
bool nodewatch = true;
|
||||||
|
|
||||||
|
void InitWatch();
|
||||||
|
void ExitWatch();
|
||||||
|
void StartWatch(media_node node);
|
||||||
|
void StopWatch(media_node node);
|
||||||
|
|
||||||
|
void InitWatch()
|
||||||
|
{
|
||||||
|
if (globalwatch) {
|
||||||
|
status_t rv;
|
||||||
|
rv = roster->StartWatching(be_app_messenger);
|
||||||
|
if (rv != B_OK) {
|
||||||
|
printf("Globalwatch: StartWatching failed. result = %#x\n",rv);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (nodewatch) {
|
||||||
|
live_node_info out_live_nodes[100];
|
||||||
|
int32 io_total_count = 100;
|
||||||
|
status_t rv;
|
||||||
|
|
||||||
|
rv = roster->GetLiveNodes(out_live_nodes, &io_total_count);
|
||||||
|
if (rv != B_OK) {
|
||||||
|
printf("GetLiveNodes failed. result = %#x\n",rv);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < io_total_count; i++)
|
||||||
|
StartWatch(out_live_nodes[i].node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ExitWatch()
|
||||||
|
{
|
||||||
|
if (globalwatch) {
|
||||||
|
status_t rv;
|
||||||
|
rv = roster->StopWatching(be_app_messenger);
|
||||||
|
if (rv != B_OK) {
|
||||||
|
printf("Globalwatch: StopWatching failed. result = %#x\n",rv);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (nodewatch) {
|
||||||
|
media_node *mn;
|
||||||
|
while ((mn = (media_node *) watchlist.ItemAt(0)) != 0)
|
||||||
|
StopWatch(*mn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void StartWatch(media_node node)
|
||||||
|
{
|
||||||
|
if (nodewatch) {
|
||||||
|
status_t rv;
|
||||||
|
rv = roster->StartWatching(be_app_messenger, node, B_MEDIA_WILDCARD);
|
||||||
|
if (rv != B_OK) {
|
||||||
|
printf("Nodewatch: StartWatching failed. result = %#x\n",rv);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
media_node *mn = new media_node;
|
||||||
|
*mn = node;
|
||||||
|
watchlist.AddItem(mn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void StopWatch(media_node node)
|
||||||
|
{
|
||||||
|
if (nodewatch) {
|
||||||
|
status_t rv;
|
||||||
|
rv = roster->StopWatching(be_app_messenger, node, B_MEDIA_WILDCARD);
|
||||||
|
if (rv != B_OK) {
|
||||||
|
printf("Nodewatch: StopWatching failed. result = %#x\n",rv);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
media_node *mn;
|
||||||
|
for (int i = 0; (mn = (media_node *) watchlist.ItemAt(i)) != 0; i++) {
|
||||||
|
if (*mn == node) {
|
||||||
|
watchlist.RemoveItem(mn);
|
||||||
|
delete mn;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class App : public BApplication
|
class App : public BApplication
|
||||||
{
|
{
|
||||||
@ -27,7 +114,11 @@ void
|
|||||||
App::ReadyToRun()
|
App::ReadyToRun()
|
||||||
{
|
{
|
||||||
roster = BMediaRoster::Roster();
|
roster = BMediaRoster::Roster();
|
||||||
printf("start watching result = %#x\n",roster->StartWatching(be_app_messenger));
|
globalwatch = (1 == (new BAlert("","Global watching?","No","Yes"))->Go());
|
||||||
|
nodewatch = (1 == (new BAlert("","Node watching?","No","Yes"))->Go());
|
||||||
|
printf("Global watching : %s\n",globalwatch ? "Yes" : "No");
|
||||||
|
printf("Node watching : %s\n",nodewatch ? "Yes" : "No");
|
||||||
|
InitWatch();
|
||||||
(new BAlert("","Click Quit to gracefully quit or Abort to abort :-)","Quit","Abort"))->Go(new BInvoker(new BMessage('quit'),be_app_messenger));
|
(new BAlert("","Click Quit to gracefully quit or Abort to abort :-)","Quit","Abort"))->Go(new BInvoker(new BMessage('quit'),be_app_messenger));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,7 +132,7 @@ App::MessageReceived(BMessage *msg)
|
|||||||
switch (msg->what) {
|
switch (msg->what) {
|
||||||
case 'quit':
|
case 'quit':
|
||||||
if (0 == msg->FindInt32("which")) // Quit
|
if (0 == msg->FindInt32("which")) // Quit
|
||||||
printf("stop watching result = %#x\n",roster->StopWatching(be_app_messenger));
|
ExitWatch();
|
||||||
be_app->PostMessage(B_QUIT_REQUESTED);
|
be_app->PostMessage(B_QUIT_REQUESTED);
|
||||||
return;
|
return;
|
||||||
case BMediaNode::B_NODE_FAILED_START:
|
case BMediaNode::B_NODE_FAILED_START:
|
||||||
|
Loading…
Reference in New Issue
Block a user