1 /* 2 * Copyright 2002, Marcus Overhagen. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #include <stdio.h> 6 #include <List.h> 7 #include <Invoker.h> 8 #include <Alert.h> 9 #include <Application.h> 10 #include <MediaRoster.h> 11 12 BMediaRoster *roster; 13 BList watchlist; 14 bool globalwatch = true; 15 bool nodewatch = true; 16 17 void InitWatch(); 18 void ExitWatch(); 19 void StartWatch(media_node node); 20 void StopWatch(media_node node); 21 22 void InitWatch() 23 { 24 if (globalwatch) { 25 status_t rv; 26 rv = roster->StartWatching(be_app_messenger); 27 if (rv != B_OK) { 28 printf("Globalwatch: StartWatching failed. result = %#lx\n",rv); 29 return; 30 } 31 } 32 if (nodewatch) { 33 live_node_info out_live_nodes[100]; 34 int32 io_total_count = 100; 35 status_t rv; 36 37 rv = roster->GetLiveNodes(out_live_nodes, &io_total_count); 38 if (rv != B_OK) { 39 printf("GetLiveNodes failed. result = %#lx\n",rv); 40 return; 41 } 42 43 for (int i = 0; i < io_total_count; i++) 44 StartWatch(out_live_nodes[i].node); 45 } 46 } 47 48 void ExitWatch() 49 { 50 if (globalwatch) { 51 status_t rv; 52 rv = roster->StopWatching(be_app_messenger); 53 if (rv != B_OK) { 54 printf("Globalwatch: StopWatching failed. result = %#lx\n",rv); 55 return; 56 } 57 } 58 if (nodewatch) { 59 media_node *mn; 60 while ((mn = (media_node *) watchlist.ItemAt(0)) != 0) 61 StopWatch(*mn); 62 } 63 } 64 65 void StartWatch(media_node node) 66 { 67 if (nodewatch) { 68 status_t rv; 69 rv = roster->StartWatching(be_app_messenger, node, B_MEDIA_WILDCARD); 70 if (rv != B_OK) { 71 printf("Nodewatch: StartWatching failed. result = %#lx\n",rv); 72 return; 73 } 74 media_node *mn = new media_node; 75 *mn = node; 76 watchlist.AddItem(mn); 77 } 78 } 79 80 void StopWatch(media_node node) 81 { 82 if (nodewatch) { 83 status_t rv; 84 rv = roster->StopWatching(be_app_messenger, node, B_MEDIA_WILDCARD); 85 if (rv != B_OK) { 86 printf("Nodewatch: StopWatching failed. result = %#lx\n",rv); 87 return; 88 } 89 media_node *mn; 90 for (int i = 0; (mn = (media_node *) watchlist.ItemAt(i)) != 0; i++) { 91 if (*mn == node) { 92 watchlist.RemoveItem(mn); 93 delete mn; 94 break; 95 } 96 } 97 } 98 } 99 100 class App : public BApplication 101 { 102 public: 103 App(const char *sig); 104 void ReadyToRun(); 105 void MessageReceived(BMessage *msg); 106 }; 107 108 App::App(const char *sig) 109 : BApplication(sig) 110 { 111 } 112 113 void 114 App::ReadyToRun() 115 { 116 roster = BMediaRoster::Roster(); 117 globalwatch = (1 == (new BAlert("","Global watching?","No","Yes"))->Go()); 118 nodewatch = (1 == (new BAlert("","Node watching?","No","Yes"))->Go()); 119 printf("Global watching : %s\n",globalwatch ? "Yes" : "No"); 120 printf("Node watching : %s\n",nodewatch ? "Yes" : "No"); 121 InitWatch(); 122 (new BAlert("","Click Quit to gracefully quit or Abort to abort :-)","Quit","Abort"))->Go(new BInvoker(new BMessage('quit'),be_app_messenger)); 123 } 124 125 void 126 App::MessageReceived(BMessage *msg) 127 { 128 if (msg->what == 0x42524157) // eat this 129 return; 130 131 printf("\n"); 132 switch (msg->what) { 133 case 'quit': 134 if (0 == msg->FindInt32("which")) // Quit 135 ExitWatch(); 136 be_app->PostMessage(B_QUIT_REQUESTED); 137 return; 138 case BMediaNode::B_NODE_FAILED_START: 139 printf("BMediaNode::B_NODE_FAILED_START:\n"); 140 break; 141 case BMediaNode::B_NODE_FAILED_STOP: 142 printf("BMediaNode::B_NODE_FAILED_STOP:\n"); 143 break; 144 case BMediaNode::B_NODE_FAILED_SEEK: 145 printf("BMediaNode::B_NODE_FAILED_SEEK:\n"); 146 break; 147 case BMediaNode::B_NODE_FAILED_SET_RUN_MODE: 148 printf("BMediaNode::B_NODE_FAILED_SET_RUN_MODE:\n"); 149 break; 150 case BMediaNode::B_NODE_FAILED_TIME_WARP: 151 printf("BMediaNode::B_NODE_FAILED_TIME_WARP:\n"); 152 break; 153 case BMediaNode::B_NODE_FAILED_PREROLL: 154 printf("BMediaNode::B_NODE_FAILED_PREROLL:\n"); 155 break; 156 case BMediaNode::B_NODE_FAILED_SET_TIME_SOURCE_FOR: 157 printf("BMediaNode::B_NODE_FAILED_SET_TIME_SOURCE_FOR:\n"); 158 break; 159 case BMediaNode::B_NODE_IN_DISTRESS: 160 printf("BMediaNode::B_NODE_IN_DISTRESS:\n"); 161 break; 162 case B_MEDIA_NODE_CREATED: 163 printf("B_MEDIA_NODE_CREATED:\n"); 164 break; 165 case B_MEDIA_NODE_DELETED: 166 printf("B_MEDIA_NODE_DELETED:\n"); 167 break; 168 case B_MEDIA_CONNECTION_MADE: 169 printf("B_MEDIA_CONNECTION_MADE:\n"); 170 break; 171 case B_MEDIA_CONNECTION_BROKEN: 172 printf("B_MEDIA_CONNECTION_BROKEN:\n"); 173 break; 174 case B_MEDIA_BUFFER_CREATED: 175 printf("B_MEDIA_BUFFER_CREATED:\n"); 176 break; 177 case B_MEDIA_BUFFER_DELETED: 178 printf("B_MEDIA_BUFFER_DELETED:\n"); 179 break; 180 case B_MEDIA_TRANSPORT_STATE: 181 printf("B_MEDIA_TRANSPORT_STATE:\n"); 182 break; 183 case B_MEDIA_PARAMETER_CHANGED: 184 printf("B_MEDIA_PARAMETER_CHANGED:\n"); 185 break; 186 case B_MEDIA_FORMAT_CHANGED: 187 printf("B_MEDIA_FORMAT_CHANGED:\n"); 188 break; 189 case B_MEDIA_WEB_CHANGED: 190 printf("B_MEDIA_WEB_CHANGED:\n"); 191 break; 192 case B_MEDIA_DEFAULT_CHANGED: 193 printf("B_MEDIA_DEFAULT_CHANGED:\n"); 194 break; 195 case B_MEDIA_NEW_PARAMETER_VALUE: 196 printf("B_MEDIA_NEW_PARAMETER_VALUE:\n"); 197 break; 198 case B_MEDIA_NODE_STOPPED: 199 printf("B_MEDIA_NODE_STOPPED:\n"); 200 break; 201 case B_MEDIA_FLAVORS_CHANGED: 202 printf("B_MEDIA_FLAVORS_CHANGED:\n"); 203 break; 204 default: 205 printf("unknown message:\n"); 206 } 207 msg->PrintToStream(); 208 } 209 210 int main() 211 { 212 App app("application/x-vnd.OpenBeOS-NotificationTest"); 213 app.Run(); 214 return 0; 215 } 216 217