blob: e77b7549023180ddedfef151e6cde17b634536f2 [file] [log] [blame]
adamdunkelsa2f3c422004-09-12 20:24:53 +00001/*
2 * Copyright (c) 2004, Swedish Institute of Computer Science.
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 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the Institute nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * This file is part of the Contiki operating system.
30 *
31 * Author: Adam Dunkels <adam@sics.se>
32 *
adamdunkelsd393e302005-02-07 07:50:35 +000033 * $Id: ek-service.c,v 1.6 2005/02/07 07:50:35 adamdunkels Exp $
adamdunkelsa2f3c422004-09-12 20:24:53 +000034 */
adamdunkelsa8c2b492004-07-04 15:01:58 +000035
36#include "ek-service.h"
37
oliverschmidte80a47f2004-08-12 13:41:11 +000038#include "log.h"
39
adamdunkelsa8c2b492004-07-04 15:01:58 +000040/*---------------------------------------------------------------------------*/
41ek_id_t
42ek_service_start(const char *name, struct ek_proc *p)
43{
44 ek_id_t service;
45
46 service = ek_find(name);
47
48 if(service == EK_ID_NONE) {
adamdunkels124723c2004-08-09 20:36:04 +000049 log_message("ek-service: starting ", name);
adamdunkelsa8c2b492004-07-04 15:01:58 +000050 return ek_start(p);
51 } else {
adamdunkels124723c2004-08-09 20:36:04 +000052 log_message("ek-service: replacing ", name);
53 ek_post_synch(service, EK_EVENT_REQUEST_REPLACE, p);
adamdunkelsa8c2b492004-07-04 15:01:58 +000054 return service;
55 }
56
57}
58/*---------------------------------------------------------------------------*/
59ek_err_t
60ek_service_find(struct ek_service *s)
61{
62 ek_id_t id;
63 id = ek_find(s->name);
64 s->id = id;
65 if(s->id == EK_ID_NONE) {
66 return EK_ERR_NOTFOUND;
67 }
68 return EK_ERR_OK;
69}
70/*---------------------------------------------------------------------------*/
71void *
72ek_service_state(struct ek_service *s)
73{
74 if(s->id == EK_ID_NONE) {
75 if(ek_service_find(s) == EK_ERR_NOTFOUND) {
76 return NULL;
77 }
78 }
79 return ek_procstate(s->id);
80}
81/*---------------------------------------------------------------------------*/
adamdunkels4e852942004-09-12 07:21:45 +000082void
83ek_service_reset(struct ek_service *s)
84{
85 log_message("ek-service: reseting ", s->name);
86 s->id = EK_ID_NONE;
87}
88/*---------------------------------------------------------------------------*/
adamdunkels124723c2004-08-09 20:36:04 +000089#if 0
90unsigned char
91ek_service_ref(struct ek_service *s)
adamdunkelsa8c2b492004-07-04 15:01:58 +000092{
adamdunkels124723c2004-08-09 20:36:04 +000093}
94/*---------------------------------------------------------------------------*/
95unsigned char
96ek_service_unref(struct ek_service *s)
97{
98}
99#endif
adamdunkelsa8c2b492004-07-04 15:01:58 +0000100/*---------------------------------------------------------------------------*/
101