Sophie

Sophie

distrib > Mandriva > 9.0 > i586 > by-pkgid > 98e91bc877e03cf3582cd163550eb7e3 > files > 1098

kernel-doc-html-2.4.19-16mdk.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<HTML
><HEAD
><TITLE
>Opening And Closing The Radio</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="Video4Linux Programming"
HREF="book1.html"><LINK
REL="UP"
TITLE="Radio Devices"
HREF="c24.html"><LINK
REL="PREVIOUS"
TITLE="Radio Devices"
HREF="c24.html"><LINK
REL="NEXT"
TITLE="The Ioctl Interface"
HREF="x73.html"></HEAD
><BODY
CLASS="SECT1"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Video4Linux Programming</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="c24.html"
ACCESSKEY="P"
>&#60;&#60;&#60; Previous</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Radio Devices</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="x73.html"
ACCESSKEY="N"
>Next &#62;&#62;&#62;</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="OPENRADIO"
></A
>Opening And Closing The Radio</H1
><P
>        The functions we declared in our video_device are mostly very simple.
        Firstly we can drop in what is basically standard code for open and close. 
  </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>&#13;
static int users = 0;

static int radio_open(stuct video_device *dev, int flags)
{
        if(users)
                return -EBUSY;
        users++;
        MOD_INC_USE_COUNT;
        return 0;
}

  </PRE
></TD
></TR
></TABLE
><P
>        At open time we need to do nothing but check if someone else is also using
        the radio card. If nobody is using it we make a note that we are using it,
        then we ensure that nobody unloads our driver on us.
  </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>&#13;
static int radio_close(struct video_device *dev)
{
        users--;
        MOD_DEC_USE_COUNT;
}

  </PRE
></TD
></TR
></TABLE
><P
>        At close time we simply need to reduce the user count and allow the module
        to become unloadable.
  </P
><P
>        If you are sharp you will have noticed neither the open nor the close
        routines attempt to reset or change the radio settings. This is intentional.
        It allows an application to set up the radio and exit. It avoids a user
        having to leave an application running all the time just to listen to the
        radio. 
  </P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="c24.html"
ACCESSKEY="P"
>&#60;&#60;&#60; Previous</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="book1.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="x73.html"
ACCESSKEY="N"
>Next &#62;&#62;&#62;</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Radio Devices</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="c24.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>The Ioctl Interface</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>