adamdunkels | a2f3c42 | 2004-09-12 20:24:53 +0000 | [diff] [blame] | 1 | /* |
| 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 | * |
adamdunkels | d393e30 | 2005-02-07 07:50:35 +0000 | [diff] [blame] | 33 | * $Id: ek-service.c,v 1.6 2005/02/07 07:50:35 adamdunkels Exp $ |
adamdunkels | a2f3c42 | 2004-09-12 20:24:53 +0000 | [diff] [blame] | 34 | */ |
adamdunkels | a8c2b49 | 2004-07-04 15:01:58 +0000 | [diff] [blame] | 35 | |
| 36 | #include "ek-service.h" |
| 37 | |
oliverschmidt | e80a47f | 2004-08-12 13:41:11 +0000 | [diff] [blame] | 38 | #include "log.h" |
| 39 | |
adamdunkels | a8c2b49 | 2004-07-04 15:01:58 +0000 | [diff] [blame] | 40 | /*---------------------------------------------------------------------------*/ |
| 41 | ek_id_t |
| 42 | ek_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) { |
adamdunkels | 124723c | 2004-08-09 20:36:04 +0000 | [diff] [blame] | 49 | log_message("ek-service: starting ", name); |
adamdunkels | a8c2b49 | 2004-07-04 15:01:58 +0000 | [diff] [blame] | 50 | return ek_start(p); |
| 51 | } else { |
adamdunkels | 124723c | 2004-08-09 20:36:04 +0000 | [diff] [blame] | 52 | log_message("ek-service: replacing ", name); |
| 53 | ek_post_synch(service, EK_EVENT_REQUEST_REPLACE, p); |
adamdunkels | a8c2b49 | 2004-07-04 15:01:58 +0000 | [diff] [blame] | 54 | return service; |
| 55 | } |
| 56 | |
| 57 | } |
| 58 | /*---------------------------------------------------------------------------*/ |
| 59 | ek_err_t |
| 60 | ek_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 | /*---------------------------------------------------------------------------*/ |
| 71 | void * |
| 72 | ek_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 | /*---------------------------------------------------------------------------*/ |
adamdunkels | 4e85294 | 2004-09-12 07:21:45 +0000 | [diff] [blame] | 82 | void |
| 83 | ek_service_reset(struct ek_service *s) |
| 84 | { |
| 85 | log_message("ek-service: reseting ", s->name); |
| 86 | s->id = EK_ID_NONE; |
| 87 | } |
| 88 | /*---------------------------------------------------------------------------*/ |
adamdunkels | 124723c | 2004-08-09 20:36:04 +0000 | [diff] [blame] | 89 | #if 0 |
| 90 | unsigned char |
| 91 | ek_service_ref(struct ek_service *s) |
adamdunkels | a8c2b49 | 2004-07-04 15:01:58 +0000 | [diff] [blame] | 92 | { |
adamdunkels | 124723c | 2004-08-09 20:36:04 +0000 | [diff] [blame] | 93 | } |
| 94 | /*---------------------------------------------------------------------------*/ |
| 95 | unsigned char |
| 96 | ek_service_unref(struct ek_service *s) |
| 97 | { |
| 98 | } |
| 99 | #endif |
adamdunkels | a8c2b49 | 2004-07-04 15:01:58 +0000 | [diff] [blame] | 100 | /*---------------------------------------------------------------------------*/ |
| 101 | |