1    /* 
     2     * Copyright (c) 2010, Texas Instruments Incorporated
     3     * All rights reserved.
     4     *
     5     * Redistribution and use in source and binary forms, with or without
     6     * modification, are permitted provided that the following conditions
     7     * are met:
     8     *
     9     * *  Redistributions of source code must retain the above copyright
    10     *    notice, this list of conditions and the following disclaimer.
    11     *
    12     * *  Redistributions in binary form must reproduce the above copyright
    13     *    notice, this list of conditions and the following disclaimer in the
    14     *    documentation and/or other materials provided with the distribution.
    15     *
    16     * *  Neither the name of Texas Instruments Incorporated nor the names of
    17     *    its contributors may be used to endorse or promote products derived
    18     *    from this software without specific prior written permission.
    19     *
    20     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    21     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
    22     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    23     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
    24     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    25     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    26     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
    27     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
    28     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
    29     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
    30     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    31     * */
    32    /*
    33     *  ======== DriverTable.xdc ========
    34     *
    35     *
    36     */
    37    
    38    import xdc.runtime.Error;
    39    import xdc.runtime.Assert;
    40    import xdc.runtime.IGateProvider;
    41    import ti.sdo.utils.NameServer;
    42    
    43    /*! 
    44     *  DriverTable module
    45     *
    46     *  This module maintains a table of {@link IDriver#Handle}. Other modules can
    47     *  lookup these handles by name and open channels for IO. The {@link Stream}
    48     *  module will open channels using this table. All names in this table have to
    49     *  be unique.
    50     *
    51     *  This module allows addition of IDriver handles into the table at 
    52     *  configuration time as well as at runtime. However, the total number of 
    53     *  runtime entries have to be decided at configuration time. There is no limit
    54     *  to entries added statically.
    55     *
    56     *  This module uses {@link ti.sdo.utils.NameServer} to maintain its table
    57     */
    58     
    59    module DriverTable {
    60        /*! 
    61         *  Max runtime entries that can be added.
    62         *
    63         *  Currently this module requires total number of entries that need
    64         *  to be added at runtime to be identified at configuration time.
    65         */
    66        config UInt maxRuntimeEntries = 0;
    67        
    68        /*! 
    69         *  Gate used to make the table thread safe.
    70         */
    71        config IGateProvider.Handle gate = null;
    72        
    73        /*! 
    74         *  Length, in MAUs, of the name field in the table.
    75         */
    76        config UInt maxNameLen = 16;
    77    
    78        /*! 
    79         *  Section name is used to place the IDriver table.
    80         */
    81        metaonly config String tableSection = null;
    82            
    83        /*!
    84         *  ======== add ========
    85         *  Add IDriver handle to the table at runtime.
    86         *
    87         *  Will raise an error when name already exists in table.
    88         *  This API is not thread safe. Set {@link #gate} parameter
    89         *  to protect table if called from multiple threads.
    90         *
    91         *  @param(name)            name of entry
    92         *  @param(driverHandle)    {@link IDriver#Handle}
    93         *  @param(eb)              Error Block
    94         */
    95        Void add(String name, IDriver.Handle driverHandle, Error.Block *eb);
    96    
    97        /*!
    98         *  ======== addMeta ========
    99         *  Add to IDriver handle to the table at configuration time.
   100         *
   101         *  @param(name)            name of entry
   102         *  @param(driverHandle)    {@link IDriver#Handle}
   103         */
   104        metaonly Void addMeta(String name, IDriver.Handle driverHandle);
   105    
   106        /*!
   107         *  ======== remove ========
   108         *  Remove entry from IDriver table at runtime.
   109         *
   110         *  Will raise an error when name not found in table
   111         *  This API is not thread safe. Set {@link #gate} parameter
   112         *  to protect table if called from multiple threads.
   113         *
   114         *  @param(name)    name of entry
   115         *  @param(eb)      error block
   116         */
   117        Void remove(String name, Error.Block *eb);
   118    
   119        /*!
   120         *  ======== match ========
   121         *  @_nodoc
   122         *  match entry in IDriver table.
   123         *
   124         *  This function matches the name with table entries and writes to
   125         *  the handle if it finds a match. If entry is not found it sets
   126         *  handle to null. It returns length matched.
   127         *  This API is not thread safe. Set {@link #gate} parameter
   128         *  to protect table if called from multiple threads.
   129         *
   130         *  @param(name)    name of entry
   131         *  @param(handle)  pointer to IDriver handle.
   132         *  @param(eb)      error block
   133         *  @b(returns)     length matched
   134         */
   135        Int match(String name, IDriver.Handle *handle, Error.Block *eb);
   136    
   137    internal:
   138    
   139        /*!
   140         * Structure of entry in metaonly table
   141         */
   142        struct Entry {
   143            String  name;
   144            Ptr     handle;
   145        };
   146    
   147        /*! 
   148         *  Array for all statically configured table entries 
   149         */
   150        metaonly config Entry staticEntries[];
   151            
   152        struct Module_State {
   153            NameServer.Handle   drvTable;
   154        };
   155    }
   156    /*
   157     *  @(#) ti.sdo.io; 1, 0, 0, 0,348; 8-10-2010 17:48:23; /db/vtree/library/trees/ipc/ipc-e23x/src/
   158     */
   159