~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
cvs/emstar/link/liblink/lqe_client.c


  1 /*
  2  *
  3  * Copyright (c) 2003 The Regents of the University of California.  All 
  4  * 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  * - Redistributions of source code must retain the above copyright
 11  *   notice, this list of conditions and the following disclaimer.
 12  *
 13  * - Neither the name of the University nor the names of its
 14  *   contributors may be used to endorse or promote products derived
 15  *   from this software without specific prior written permission.
 16  *
 17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
 18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 19  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 20  * PARTICULAR  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
 21  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 23  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 24  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 25  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 28  *
 29  */
 30  
 31 
 32 /*
 33  * liblink/lqe_client.c: A helper library for talking to the
 34  * lqe daemon.
 35  *
 36  * $Id: lqe_client.c,v 1.1 2005-01-26 01:27:24 cerpa Exp $
 37  */
 38 
 39 char lqe_client_c_cvsid[] = "$Id: lqe_client.c,v 1.1 2005-01-26 01:27:24 cerpa Exp $";
 40 
 41 #include <stdio.h>
 42 #include <stdlib.h>
 43 
 44 #include "libdev/status_client.h"
 45 #include "link/link.h"
 46 #include "link/lqe.h"
 47 
 48 
 49 static void lqe_list_destroy(void *data, g_event_t *event)
 50 {
 51   /* free the copy of the opts that we made when the event was created */
 52   free(data);
 53 }
 54 
 55 
 56 /* When the status client code tells us that we have new data */
 57 static int lqe_list_dispatch(void *new_buffer, size_t size, void *data)
 58 {
 59   int retval = EVENT_RENEW;
 60   lqe_opts_t *opts = (lqe_opts_t *) data;
 61  
 62   if (size % sizeof(neigh_t)) {
 63     elog(LOG_CRIT, "got corrupt neighborlist size %d!!", size);
 64     goto done;
 65   }
 66 
 67   if (opts->new_info)
 68     retval = (opts->new_info)((neigh_t *) new_buffer, size/sizeof(neigh_t),
 69                               opts->data);
 70 
 71  done:
 72   return retval;
 73 }
 74 
 75 
 76 /*
 77  * create an event that fires a user callback every time we get a new
 78  * neighborlist from the lqe service
 79  */
 80 int g_lqe(lqe_opts_t *lqe_opts, status_client_context_t **ref)
 81 {
 82   int retval;
 83   lqe_opts_t *opts_copy = malloc(sizeof(lqe_opts_t));
 84   status_client_opts_t sc_opts = {
 85     handler: lqe_list_dispatch,
 86     //reread_period: 1000,
 87     private_data: opts_copy,
 88     destroy: lqe_list_destroy
 89   };
 90 
 91   /* make sure malloc didn't fail */
 92   if (opts_copy == NULL) {
 93     errno = ENOMEM;
 94     retval = -1;
 95     goto done;
 96   }
 97 
 98   /* make sure user provided options */
 99   if (lqe_opts == NULL) {
100     errno = EINVAL;
101     retval = -1;
102     goto done;
103   }
104 
105   /* compute the lqe device name */
106   sc_opts.devname = link_name_s(lqe_opts->link_name, LINK_LQE_SUBDEV);
107 
108   /* make a copy of the lqe options */
109   *opts_copy = *lqe_opts;
110 
111   /* try to open the file */
112   retval = g_status_client_full(&sc_opts, ref);
113 
114  done:
115   if (retval < 0) {
116     if (opts_copy)
117       free(opts_copy);
118   }
119   return retval;
120 }
121 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.