1c284bb0fSMatt Madia/*
2c284bb0fSMatt Madia * Copyright (c) 1999-2000, Eric Moon.
3c284bb0fSMatt Madia * All rights reserved.
4c284bb0fSMatt Madia *
5c284bb0fSMatt Madia * Redistribution and use in source and binary forms, with or without
6c284bb0fSMatt Madia * modification, are permitted provided that the following conditions
7c284bb0fSMatt Madia * are met:
8c284bb0fSMatt Madia *
9c284bb0fSMatt Madia * 1. Redistributions of source code must retain the above copyright
10c284bb0fSMatt Madia *    notice, this list of conditions, and the following disclaimer.
11c284bb0fSMatt Madia *
12c284bb0fSMatt Madia * 2. Redistributions in binary form must reproduce the above copyright
13c284bb0fSMatt Madia *    notice, this list of conditions, and the following disclaimer in the
14c284bb0fSMatt Madia *    documentation and/or other materials provided with the distribution.
15c284bb0fSMatt Madia *
16c284bb0fSMatt Madia * 3. The name of the author may not be used to endorse or promote products
17c284bb0fSMatt Madia *    derived from this software without specific prior written permission.
18c284bb0fSMatt Madia *
19c284bb0fSMatt Madia * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
20c284bb0fSMatt Madia * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21c284bb0fSMatt Madia * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22c284bb0fSMatt Madia * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23c284bb0fSMatt Madia * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24c284bb0fSMatt Madia * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25c284bb0fSMatt Madia * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26c284bb0fSMatt Madia * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
27c284bb0fSMatt Madia * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28c284bb0fSMatt Madia * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29c284bb0fSMatt Madia */
30c284bb0fSMatt Madia
31c284bb0fSMatt Madia
32a0795c6fSMarcus Overhagen// LiveNodeInfoView.cpp
33a0795c6fSMarcus Overhagen
34a0795c6fSMarcus Overhagen#include "LiveNodeInfoView.h"
35a0795c6fSMarcus Overhagen// InfoView
36a0795c6fSMarcus Overhagen#include "InfoWindowManager.h"
37a0795c6fSMarcus Overhagen// NodeManager
38a0795c6fSMarcus Overhagen#include "NodeGroup.h"
39a0795c6fSMarcus Overhagen#include "NodeRef.h"
40a0795c6fSMarcus Overhagen// Support
41a0795c6fSMarcus Overhagen#include "MediaIcon.h"
42a0795c6fSMarcus Overhagen#include "MediaString.h"
43a0795c6fSMarcus Overhagen
44a0795c6fSMarcus Overhagen// Media Kit
45a0795c6fSMarcus Overhagen#include <MediaNode.h>
46a0795c6fSMarcus Overhagen
47a0795c6fSMarcus Overhagen// Interface Kit
48a0795c6fSMarcus Overhagen#include <Window.h>
49a0795c6fSMarcus Overhagen
50a0795c6fSMarcus Overhagen__USE_CORTEX_NAMESPACE
51a0795c6fSMarcus Overhagen
52a0795c6fSMarcus Overhagen#include <Debug.h>
53a0795c6fSMarcus Overhagen#define D_METHOD(x) //PRINT (x)
54a0795c6fSMarcus Overhagen#define D_MESSAGE(x) //PRINT (x)
55a0795c6fSMarcus Overhagen
56a0795c6fSMarcus Overhagen// -------------------------------------------------------- //
57a0795c6fSMarcus Overhagen// *** ctor/dtor (public)
58a0795c6fSMarcus Overhagen// -------------------------------------------------------- //
59a0795c6fSMarcus Overhagen
60a0795c6fSMarcus OverhagenLiveNodeInfoView::LiveNodeInfoView(
61a0795c6fSMarcus Overhagen	const NodeRef *ref)
62a0795c6fSMarcus Overhagen	: InfoView(ref->name(), "Live Media Node",
63a0795c6fSMarcus Overhagen			   new MediaIcon(ref->nodeInfo(), B_LARGE_ICON)),
64a0795c6fSMarcus Overhagen	  m_nodeID(ref->id())
65a0795c6fSMarcus Overhagen{
66a0795c6fSMarcus Overhagen	D_METHOD(("LiveNodeInfoView::LiveNodeInfoView()\n"));
67a0795c6fSMarcus Overhagen
68a0795c6fSMarcus Overhagen	// adjust view properties
69a0795c6fSMarcus Overhagen	setSideBarWidth(be_plain_font->StringWidth(" Run Mode ") + 2 * InfoView::M_H_MARGIN);
70a0795c6fSMarcus Overhagen
71a0795c6fSMarcus Overhagen	// add "Node ID" field
72a0795c6fSMarcus Overhagen	BString s;
73a0795c6fSMarcus Overhagen	s << ref->id();
74a0795c6fSMarcus Overhagen	addField("Node ID", s);
75a0795c6fSMarcus Overhagen
76a0795c6fSMarcus Overhagen	// add "Port" field
77a0795c6fSMarcus Overhagen	s = "";
78a0795c6fSMarcus Overhagen	s << ref->node().port;
79a0795c6fSMarcus Overhagen	port_info portInfo;
80a0795c6fSMarcus Overhagen	if (get_port_info(ref->node().port, &portInfo) == B_OK)
81a0795c6fSMarcus Overhagen	{
82a0795c6fSMarcus Overhagen		s << " (" << portInfo.name << ")";
83a0795c6fSMarcus Overhagen	}
84a0795c6fSMarcus Overhagen	addField("Port", s);
85a0795c6fSMarcus Overhagen
86a0795c6fSMarcus Overhagen	// add separator field
87a0795c6fSMarcus Overhagen	addField("", "");
88a0795c6fSMarcus Overhagen
89a0795c6fSMarcus Overhagen	// add "Kinds" field
90a0795c6fSMarcus Overhagen	addField("Kinds", MediaString::getStringFor(static_cast<node_kind>(ref->kind())));
91a0795c6fSMarcus Overhagen
92a0795c6fSMarcus Overhagen	// add "Run Mode" field
93a0795c6fSMarcus Overhagen	BMediaNode::run_mode runMode = static_cast<BMediaNode::run_mode>(ref->runMode());
94a0795c6fSMarcus Overhagen	if (runMode < 1)
95a0795c6fSMarcus Overhagen	{
96a0795c6fSMarcus Overhagen		NodeGroup *group = ref->group();
97a0795c6fSMarcus Overhagen		if (group)
98a0795c6fSMarcus Overhagen		{
99a0795c6fSMarcus Overhagen			runMode = group->runMode();
100a0795c6fSMarcus Overhagen		}
101a0795c6fSMarcus Overhagen	}
102a0795c6fSMarcus Overhagen	addField("Run Mode", MediaString::getStringFor(runMode));
103a0795c6fSMarcus Overhagen
104a0795c6fSMarcus Overhagen	// add "Latency" field
105a0795c6fSMarcus Overhagen	bigtime_t latency;
106a0795c6fSMarcus Overhagen	if (ref->totalLatency(&latency) == B_OK)
107a0795c6fSMarcus Overhagen	{
108a0795c6fSMarcus Overhagen		s = "";
109a0795c6fSMarcus Overhagen		if (latency > 0)
110a0795c6fSMarcus Overhagen		{
111a0795c6fSMarcus Overhagen			s << static_cast<float>(latency) / 1000.0f << " ms";
112a0795c6fSMarcus Overhagen		}
113a0795c6fSMarcus Overhagen		else
114a0795c6fSMarcus Overhagen		{
115a0795c6fSMarcus Overhagen			s = "?";
116a0795c6fSMarcus Overhagen		}
117a0795c6fSMarcus Overhagen		addField("Latency", s);
118a0795c6fSMarcus Overhagen	}
119a0795c6fSMarcus Overhagen}
120a0795c6fSMarcus Overhagen
121a0795c6fSMarcus OverhagenLiveNodeInfoView::~LiveNodeInfoView() {
122a0795c6fSMarcus Overhagen	D_METHOD(("LiveNodeInfoView::~LiveNodeInfoView()\n"));
123a0795c6fSMarcus Overhagen
124a0795c6fSMarcus Overhagen}
125a0795c6fSMarcus Overhagen
126a0795c6fSMarcus Overhagen// -------------------------------------------------------- //
127a0795c6fSMarcus Overhagen// *** BView implementation (public)
128a0795c6fSMarcus Overhagen// -------------------------------------------------------- //
129a0795c6fSMarcus Overhagen
130a0795c6fSMarcus Overhagenvoid LiveNodeInfoView::DetachedFromWindow() {
131a0795c6fSMarcus Overhagen	D_METHOD(("LiveNodeInfoView::DetachedFromWindow()\n"));
132a0795c6fSMarcus Overhagen
133a0795c6fSMarcus Overhagen	InfoWindowManager *manager = InfoWindowManager::Instance();
134a0795c6fSMarcus Overhagen	if (manager) {
135a0795c6fSMarcus Overhagen		BMessage message(InfoWindowManager::M_LIVE_NODE_WINDOW_CLOSED);
136a0795c6fSMarcus Overhagen		message.AddInt32("nodeID", m_nodeID);
137a0795c6fSMarcus Overhagen		manager->PostMessage(&message);
138a0795c6fSMarcus Overhagen	}
139a0795c6fSMarcus Overhagen}
140a0795c6fSMarcus Overhagen
141a0795c6fSMarcus Overhagen// END -- LiveNodeInfoView.cpp --
142