Opening And Closing The Radio
Prev | Chapter 2. Radio Devices | Next

## Opening And Closing The Radio

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.

    static int users = 0;

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

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.

    static int radio_close(struct video_device *dev)
    {
            users--;
    }

At close time we simply need to reduce the user count and allow the module to become unloadable.

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.

Prev | Up | Next
Chapter 2. Radio Devices | Home | The Ioctl Interface