xref: /haiku/src/apps/cortex/addons/LoggingConsumer/LoggingConsumerAddOn.cpp (revision fce4895d1884da5ae6fb299d23c735c598e690b1)
1 /*
2  * Copyright 1991-1999, Be Incorporated.
3  * Copyright (c) 1999-2000, Eric Moon.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions, and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions, and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * 3. The name of the author may not be used to endorse or promote products
18  *    derived from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22  * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
24  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
28  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 
33 // LoggingConsumerAddOn.cpp
34 // e.moon 4jun99
35 
36 #include "LoggingConsumer.h"
37 #include "LoggingConsumerAddOn.h"
38 #include <Entry.h>
39 #include <Debug.h>
40 #include <cstring>
41 #include <cstdlib>
42 
43 // logfile path
44 const char* const		g_pLogPath = "/tmp/node_log";
45 
46 
47 // instantiation function
48 extern "C" _EXPORT BMediaAddOn* make_media_addon(image_id image) {
49 	return new LoggingConsumerAddOn(image);
50 }
51 
52 // -------------------------------------------------------- //
53 // ctor/dtor
54 // -------------------------------------------------------- //
55 
56 LoggingConsumerAddOn::~LoggingConsumerAddOn() {
57 	PRINT(("~LoggingConsumerAddOn()\n"));
58 }
59 LoggingConsumerAddOn::LoggingConsumerAddOn(image_id image) :
60 	BMediaAddOn(image) {}
61 
62 // -------------------------------------------------------- //
63 // BMediaAddOn impl
64 // -------------------------------------------------------- //
65 
66 status_t LoggingConsumerAddOn::InitCheck(
67 	const char** out_failure_text) {
68 	return B_OK;
69 }
70 
71 int32 LoggingConsumerAddOn::CountFlavors() {
72 	return 1;
73 }
74 
75 status_t LoggingConsumerAddOn::GetFlavorAt(
76 	int32 n,
77 	const flavor_info** out_info) {
78 	if(n)
79 		return B_ERROR;
80 
81 	flavor_info* pInfo = new flavor_info;
82 	pInfo->internal_id = n;
83 	pInfo->name = (char*)"LoggingConsumer";
84 	pInfo->info = (char*)"An add-on version of the LoggingConsumer node.\n"
85 		"See the Be Developer Newsletter III.18: 5 May, 1999\n"
86 		"adapted by Eric Moon (4 June, 1999)";
87 	pInfo->kinds = B_BUFFER_CONSUMER | B_CONTROLLABLE;
88 	pInfo->flavor_flags = 0;
89 	pInfo->possible_count = 0;
90 
91 	pInfo->in_format_count = 1;
92 	media_format* pFormat = new media_format;
93 	pFormat->type = B_MEDIA_UNKNOWN_TYPE;
94 	pInfo->in_formats = pFormat;
95 
96 	pInfo->out_format_count = 0;
97 	pInfo->out_formats = 0;
98 
99 
100 	*out_info = pInfo;
101 	return B_OK;
102 }
103 
104 BMediaNode* LoggingConsumerAddOn::InstantiateNodeFor(
105 	const flavor_info* info,
106 	BMessage* config,
107 	status_t* out_error) {
108 
109 	// initialize log file
110 	entry_ref ref;
111 	get_ref_for_path(g_pLogPath, &ref);
112 	LoggingConsumer* pNode = new LoggingConsumer(ref, this);
113 
114 	// trim down the log's verbosity a touch
115 	pNode->SetEnabled(LOG_HANDLE_EVENT, false);
116 
117 	return pNode;
118 }
119 
120 status_t LoggingConsumerAddOn::GetConfigurationFor(
121 	BMediaNode* your_node,
122 	BMessage* into_message) {
123 
124 	// no config yet
125 	return B_OK;
126 }
127 
128 // END -- LoggingConsumerAddOn.cpp
129