LCOV - code coverage report
Current view: top level - pulsecore - shared.c (source / functions) Hit Total Coverage
Test: lcov.out Lines: 0 41 0.0 %
Date: 2012-07-17 Functions: 0 5 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 42 0.0 %

           Branch data     Line data    Source code
       1                 :            : /***
       2                 :            :   This file is part of PulseAudio.
       3                 :            : 
       4                 :            :   Copyright 2004-2006 Lennart Poettering
       5                 :            : 
       6                 :            :   PulseAudio is free software; you can redistribute it and/or modify
       7                 :            :   it under the terms of the GNU Lesser General Public License as published
       8                 :            :   by the Free Software Foundation; either version 2.1 of the License,
       9                 :            :   or (at your option) any later version.
      10                 :            : 
      11                 :            :   PulseAudio is distributed in the hope that it will be useful, but
      12                 :            :   WITHOUT ANY WARRANTY; without even the implied warranty of
      13                 :            :   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
      14                 :            :   General Public License for more details.
      15                 :            : 
      16                 :            :   You should have received a copy of the GNU Lesser General Public License
      17                 :            :   along with PulseAudio; if not, write to the Free Software
      18                 :            :   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
      19                 :            :   USA.
      20                 :            : ***/
      21                 :            : 
      22                 :            : #ifdef HAVE_CONFIG_H
      23                 :            : #include <config.h>
      24                 :            : #endif
      25                 :            : 
      26                 :            : #include <pulse/xmalloc.h>
      27                 :            : #include <pulsecore/macro.h>
      28                 :            : 
      29                 :            : #include "shared.h"
      30                 :            : 
      31                 :            : typedef struct pa_shared {
      32                 :            :     char *name;  /* Points to memory allocated by the shared property system */
      33                 :            :     void *data;  /* Points to memory maintained by the caller */
      34                 :            : } pa_shared;
      35                 :            : 
      36                 :            : /* Allocate a new shared property object */
      37                 :            : static pa_shared* shared_new(const char *name, void *data) {
      38                 :            :     pa_shared* p;
      39                 :            : 
      40         [ #  # ]:          0 :     pa_assert(name);
      41         [ #  # ]:          0 :     pa_assert(data);
      42                 :            : 
      43                 :          0 :     p = pa_xnew(pa_shared, 1);
      44                 :          0 :     p->name = pa_xstrdup(name);
      45                 :          0 :     p->data = data;
      46                 :            : 
      47                 :            :     return p;
      48                 :            : }
      49                 :            : 
      50                 :            : /* Free a shared property object */
      51                 :            : static void shared_free(pa_shared *p) {
      52         [ #  # ]:          0 :     pa_assert(p);
      53                 :            : 
      54                 :          0 :     pa_xfree(p->name);
      55                 :          0 :     pa_xfree(p);
      56                 :            : }
      57                 :            : 
      58                 :          0 : void* pa_shared_get(pa_core *c, const char *name) {
      59                 :            :     pa_shared *p;
      60                 :            : 
      61         [ #  # ]:          0 :     pa_assert(c);
      62         [ #  # ]:          0 :     pa_assert(name);
      63         [ #  # ]:          0 :     pa_assert(c->shared);
      64                 :            : 
      65         [ #  # ]:          0 :     if (!(p = pa_hashmap_get(c->shared, name)))
      66                 :            :         return NULL;
      67                 :            : 
      68                 :          0 :     return p->data;
      69                 :            : }
      70                 :            : 
      71                 :          0 : int pa_shared_set(pa_core *c, const char *name, void *data) {
      72                 :            :     pa_shared *p;
      73                 :            : 
      74         [ #  # ]:          0 :     pa_assert(c);
      75         [ #  # ]:          0 :     pa_assert(name);
      76         [ #  # ]:          0 :     pa_assert(data);
      77         [ #  # ]:          0 :     pa_assert(c->shared);
      78                 :            : 
      79         [ #  # ]:          0 :     if (pa_hashmap_get(c->shared, name))
      80                 :            :         return -1;
      81                 :            : 
      82                 :          0 :     p = shared_new(name, data);
      83                 :          0 :     pa_hashmap_put(c->shared, p->name, p);
      84                 :          0 :     return 0;
      85                 :            : }
      86                 :            : 
      87                 :          0 : int pa_shared_remove(pa_core *c, const char *name) {
      88                 :            :     pa_shared *p;
      89                 :            : 
      90         [ #  # ]:          0 :     pa_assert(c);
      91         [ #  # ]:          0 :     pa_assert(name);
      92         [ #  # ]:          0 :     pa_assert(c->shared);
      93                 :            : 
      94         [ #  # ]:          0 :     if (!(p = pa_hashmap_remove(c->shared, name)))
      95                 :            :         return -1;
      96                 :            : 
      97                 :            :     shared_free(p);
      98                 :          0 :     return 0;
      99                 :            : }
     100                 :            : 
     101                 :          0 : void pa_shared_dump(pa_core *c, pa_strbuf *s) {
     102                 :          0 :     void *state = NULL;
     103                 :            :     pa_shared *p;
     104                 :            : 
     105         [ #  # ]:          0 :     pa_assert(c);
     106         [ #  # ]:          0 :     pa_assert(s);
     107                 :            : 
     108         [ #  # ]:          0 :     while ((p = pa_hashmap_iterate(c->shared, &state, NULL)))
     109                 :          0 :         pa_strbuf_printf(s, "[%s] -> [%p]\n", p->name, p->data);
     110                 :          0 : }
     111                 :            : 
     112                 :          0 : int pa_shared_replace(pa_core *c, const char *name, void *data) {
     113         [ #  # ]:          0 :     pa_assert(c);
     114         [ #  # ]:          0 :     pa_assert(name);
     115                 :            : 
     116                 :          0 :     pa_shared_remove(c, name);
     117                 :          0 :     return pa_shared_set(c, name, data);
     118                 :            : }

Generated by: LCOV version 1.9