/home/hillier_g/checkout/most4linux/libnetservices/src/linux/init.c

00001 /*
00002  *  Copyright(c) Siemens AG, Muenchen, Germany, 2005, 2006, 2007
00003  *                           Bernhard Walle <bernhard.walle@gmx.de>
00004  *                           Gernot Hillier <gernot.hillier@siemens.com>
00005  *                           All rights reserved.
00006  *
00007  * ----------------------------------------------------------------------------
00008  * The contents of this file are subject to the Mozilla Public License
00009  * Version 1.1 (the "License"); you may not use this file except in
00010  * compliance with the License. You may obtain a copy of the License at
00011  * http://www.mozilla.org/MPL/
00012  * 
00013  * Software distributed under the License is distributed on an "AS IS"
00014  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
00015  * License for the specific language governing rights and limitations
00016  * under the License.
00017  *
00018  * The Original Code is Siemens code.
00019  * 
00020  * The Initial Developer of the Original Code is Siemens AG.
00021  * Portions created by the Initial Developer are Copyright (C) 2005-06
00022  * the Initial Developer. All Rights Reserved.
00023  * ----------------------------------------------------------------------------
00024  */
00025 #include <errno.h>
00026 #include <limits.h>
00027 #include <pthread.h>
00028 
00029 #include <unistd.h>
00030 #include <sys/types.h>
00031 #include <sys/stat.h>
00032 #include <sys/ioctl.h>
00033 #include <fcntl.h>
00034 
00035 #include <most-netservice.h>
00036 
00037 #include "adjust.h"
00038 #include "mostdef1.h"
00039 #include "mostns1.h"
00040 #include "mostnetsdll.h"
00041 
00042 #include "global.h"
00043 #include "service.h"
00044 
00045 /* see header file 'global.h' */
00046 int g_control_fd;
00047 
00048 /* mutex */
00049 pthread_mutex_t g_nets_mutex = PTHREAD_MUTEX_INITIALIZER;
00050 
00054 #define NETSERVICE_DEVICE_FILE      "/dev/mostnets%d"
00055 
00056 /* -------------------------------------------------------------------------- */
00057 short OpenNetServices(void)
00058 {
00059     char buffer[PATH_MAX];
00060     
00061     PRINT_TRACE();
00062 
00063     /* open the driver */
00064     snprintf(buffer, PATH_MAX, NETSERVICE_DEVICE_FILE, InstID);
00065     g_control_fd = open(buffer, O_RDWR);
00066     if (g_control_fd < 0) {
00067         PERR_DEBUG("Failed to open control driver");
00068         return E_OPEN_DRIVER;
00069     }
00070 
00071     /* initialize the NetServices */
00072     InitNetServices();
00073 
00074     /* 
00075      * create the service thread and initialize interrupt handling from
00076      * userspace 
00077      */
00078     service_thread_init();
00079 
00080     PRINT_TRACE("fd = %d", g_control_fd);
00081     
00082     return E_SUCCESS;
00083 }
00084 
00085 /* -------------------------------------------------------------------------- */
00086 void CloseNetServices(void)
00087 {
00088     PRINT_TRACE("Close NetServices, fd = %d", g_control_fd);
00089 
00090     /* destroy the service thread and unregister interrupt handling */
00091     service_thread_finish();
00092 
00093     close(g_control_fd);
00094     g_control_fd = 0;
00095 }
00096 
00097 /* vim: set ts=4 et sw=4: */

Generated on Fri Mar 9 14:48:59 2007 for MOST Adaption Layer for Netservices Library by  doxygen 1.5.0