source: mainline/uspace/srv/logger/ctl.c@ e005f92

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since e005f92 was e005f92, checked in by Vojtech Horky <vojtechhorky@…>, 13 years ago

Split logger into more files

  • Property mode set to 100644
File size: 3.6 KB
Line 
1/*
2 * Copyright (c) 2012 Vojtech Horky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/**
30 * @addtogroup logger
31 * @{
32 */
33
34/** @file
35 */
36
37#include <unistd.h>
38#include <malloc.h>
39#include <stdio.h>
40#include <errno.h>
41#include <io/logctl.h>
42#include <ipc/logger.h>
43#include "logger.h"
44
45static int handle_namespace_level_change(sysarg_t new_level)
46{
47 void *namespace_name;
48 int rc = async_data_write_accept(&namespace_name, true, 0, 0, 0, NULL);
49 if (rc != EOK) {
50 return rc;
51 }
52
53 logging_namespace_t *namespace = namespace_writer_attach((const char *) namespace_name);
54 free(namespace_name);
55 if (namespace == NULL)
56 return ENOENT;
57
58 rc = namespace_change_level(namespace, (log_level_t) new_level);
59 namespace_writer_detach(namespace);
60
61 return rc;
62}
63
64static int handle_context_level_change(sysarg_t new_level)
65{
66 void *namespace_name;
67 int rc = async_data_write_accept(&namespace_name, true, 0, 0, 0, NULL);
68 if (rc != EOK) {
69 return rc;
70 }
71
72 logging_namespace_t *namespace = namespace_writer_attach((const char *) namespace_name);
73 free(namespace_name);
74 if (namespace == NULL)
75 return ENOENT;
76
77 void *context_name;
78 rc = async_data_write_accept(&context_name, true, 0, 0, 0, NULL);
79 if (rc != EOK) {
80 namespace_writer_detach(namespace);
81 return rc;
82 }
83
84 rc = namespace_change_context_level(namespace, context_name, new_level);
85 free(context_name);
86 namespace_writer_detach(namespace);
87
88 return rc;
89}
90
91void logger_connection_handler_control(ipc_callid_t callid)
92{
93 async_answer_0(callid, EOK);
94 printf(NAME "/control: new client.\n");
95
96 while (true) {
97 ipc_call_t call;
98 ipc_callid_t callid = async_get_call(&call);
99
100 if (!IPC_GET_IMETHOD(call))
101 break;
102
103 int rc;
104
105 switch (IPC_GET_IMETHOD(call)) {
106 case LOGGER_CTL_GET_DEFAULT_LEVEL:
107 async_answer_1(callid, EOK, get_default_logging_level());
108 break;
109 case LOGGER_CTL_SET_DEFAULT_LEVEL:
110 rc = set_default_logging_level(IPC_GET_ARG1(call));
111 async_answer_0(callid, rc);
112 break;
113 case LOGGER_CTL_SET_NAMESPACE_LEVEL:
114 rc = handle_namespace_level_change(IPC_GET_ARG1(call));
115 async_answer_0(callid, rc);
116 break;
117 case LOGGER_CTL_SET_CONTEXT_LEVEL:
118 rc = handle_context_level_change(IPC_GET_ARG1(call));
119 async_answer_0(callid, rc);
120 break;
121 default:
122 async_answer_0(callid, EINVAL);
123 break;
124 }
125 }
126
127 printf(NAME "/control: client terminated.\n");
128}
129
130
131/**
132 * @}
133 */
Note: See TracBrowser for help on using the repository browser.