Ignore:
Timestamp:
Mar 22, 2011, 4:05:57 PM (13 years ago)
Author:
mies
Message:

almost forgot to commit: doxygen modules :)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • source/ariba/utility/types/LinkID.h

    r3690 r9684  
    4040#define LINKID_H_
    4141
     42#include <stdlib.h>
     43#include <stdint.h>
     44#include <stdio.h>
     45
    4246#include <vector>
    43 #include "ariba/utility/types/Identifier.h"
     47#include <string>
     48
     49#include "ariba/utility/serialization.h"
    4450
    4551using std::vector;
    46 using ariba::utility::Identifier;
    4752
    4853namespace ariba {
     
    5055
    5156/**
    52  * Represents a link from the base communication.
     57 * The link id identifies a link between two devices/nodes.
     58 *
     59 * Its a 32-bit value, that is composed out of two 16-bit values
     60 * identifing a initiator and acceptor id.
    5361 */
    54 class LinkID : public Identifier {
     62class LinkID {
     63private:
     64        uint16_t local_id;
     65        uint16_t initiator_id;
     66        uint16_t acceptor_id;
     67
     68
     69        LinkID(uint16_t local_id) {
     70                this->local_id = local_id;
     71                this->initiator_id = 0;
     72                this->acceptor_id = 0;
     73        }
     74
     75        /// returns the full id
     76        inline uint32_t getFullId() const {
     77                return (initiator_id << 16) + acceptor_id;
     78        }
     79
     80        inline int compareTo( const LinkID& rhs ) const {
     81                // compare local id
     82                if (rhs.isLocal() && this->isLocal())
     83                        return local_id - rhs.local_id;
     84
     85                // compare initiator id
     86                else if ((initiator_id == 0 || rhs.initiator_id == 0)
     87                                && (acceptor_id == rhs.acceptor_id) ) return 0;
     88
     89                // compare acceptor id
     90                else if ((acceptor_id == 0 || rhs.acceptor_id == 0)
     91                                && (initiator_id == rhs.initiator_id) ) return 0;
     92
     93                // compare full id
     94                else if (getFullId() == rhs.getFullId()) return 0;
     95                else if (getFullId() <  rhs.getFullId()) return -1;
     96                else if (getFullId() >  rhs.getFullId()) return 1;
     97                return -1;
     98        }
     99
     100        static const char* getInfo( const LinkID& id );
     101
     102        static bool isValid( const LinkID& id );
     103
    55104public:
     105        /// the unspecified link id
    56106        static const LinkID UNSPECIFIED;
    57107
    58         LinkID();
    59         LinkID(const LinkID& rh);
    60         LinkID(const Identifier& identifier);
    61         virtual ~LinkID();
    62         LinkID& operator=(const LinkID& rh);
    63 
    64         bool valid();
    65         static LinkID create();
    66 
    67 private:
    68         bool isvalid;
     108        /// create a new locally unique link id
     109        static LinkID create( const char* info = NULL );
     110
     111        /// free a locally unique link id
     112        static void destroy( const LinkID& id );
     113
     114        /// construct a unspecified id
     115        LinkID() {
     116                local_id = 0;
     117                initiator_id = 0;
     118                acceptor_id = 0;
     119        }
     120
     121        /// copy constructor
     122        LinkID( const LinkID& rh );
     123
     124        /// assigns another link id
     125        LinkID& operator=(const LinkID& rh) {
     126                local_id = rh.local_id;
     127                initiator_id = rh.initiator_id;
     128                acceptor_id = rh.acceptor_id;
     129                return *this;
     130        }
     131
     132        /// returns true, if the local link id is known and registered
     133        bool isValid() const {
     134                return isValid(*this);
     135        }
     136
     137        bool isUnspecified() const {
     138                return local_id == 0 && initiator_id == 0 && acceptor_id == 0;
     139        }
     140
     141        /// returns true, if this is a local id only
     142        bool isLocal() const {
     143                return acceptor_id == 0 && initiator_id == 0;
     144        }
     145
     146        /// returns true, if this is a remote id only
     147        bool isRemote() const {
     148                return local_id == 0;
     149        }
     150
     151        /// returns true, if this is a full link id (with acceptor/initiator id)
     152        bool isLink() const {
     153                return acceptor_id != 0 && initiator_id != 0;
     154        }
     155
     156        /// returns the local id
     157        uint16_t getLocalId() const {
     158                return local_id;
     159        }
     160
     161        /// returns the remote id
     162        uint16_t getRemoteId() const {
     163                return local_id == initiator_id ? acceptor_id : initiator_id;
     164        }
     165
     166        /// returns the initiators local link id
     167        uint16_t getInitiatorId() const {
     168                return initiator_id;
     169        }
     170
     171        /// returns the acceptors local link id
     172        uint16_t getAcceptorId() const {
     173                return acceptor_id;
     174        }
     175
     176        /// sets the local initiator id of the link
     177        /// if id is unspecified a new local id is used as initiator id
     178        void setInitiatorId( const LinkID& id = UNSPECIFIED ) {
     179                assert(initiator_id == 0);
     180                if ( id == UNSPECIFIED ) {
     181                        assert(local_id == 0);
     182                        local_id = LinkID::create().local_id;
     183                        initiator_id = local_id;
     184                } else {
     185                        assert(local_id == acceptor_id && id.local_id == 0 && id.initiator_id != 0);
     186                        initiator_id = id.initiator_id;
     187                }
     188        }
     189
     190        /// sets the local acceptor id of the link
     191        /// if id is unspecified a new local id is used as acceptor id
     192        void setAcceptorId( const LinkID& id = UNSPECIFIED ) {
     193                assert(acceptor_id == 0);
     194                if ( id == UNSPECIFIED ) {
     195                        assert(local_id == 0);
     196                        local_id = LinkID::create().local_id;
     197                        acceptor_id = local_id;
     198                } else {
     199                        assert(local_id == initiator_id && id.local_id == 0 && id.acceptor_id != 0);
     200                        acceptor_id = id.acceptor_id;
     201                }
     202        }
     203
     204        void combine( const LinkID& id ) {
     205
     206        }
     207
     208        /// returns a string representation of the link id
     209        std::string toString() const {
     210                char str[20];
     211                if (isLocal())
     212                        sprintf(str, "l%04x", local_id);
     213                else
     214                        sprintf(str, "i%04x.a%04x", initiator_id, acceptor_id );
     215                return std::string(str);
     216        }
     217
     218        /// returns the info of the link id
     219        const char* getInfo() const {
     220                return getInfo(*this);
     221        }
     222
     223        /// convenience operators
     224        bool operator==( const LinkID& rhs ) const { return compareTo(rhs) == 0; }
     225        bool operator!=( const LinkID& rhs ) const { return compareTo(rhs) != 0; }
     226        bool operator< ( const LinkID& rhs ) const { return compareTo(rhs) <  0; }
     227        bool operator<=( const LinkID& rhs ) const { return compareTo(rhs) <= 0; }
     228        bool operator> ( const LinkID& rhs ) const { return compareTo(rhs) >  0; }
     229        bool operator>=( const LinkID& rhs ) const { return compareTo(rhs) >= 0; }
    69230};
    70231
     232std::ostream& operator<<(std::ostream& s, const LinkID& id );
     233
    71234typedef vector<LinkID> LinkIDs;
    72235
    73236}} // namespace ariba, utility
    74237
     238sznBeginDefault( ariba::utility::LinkID, X ) {
     239        if (X.isDeserializer()) local_id = 0;
     240        X && initiator_id && acceptor_id;
     241} sznEnd();
     242
     243
    75244#endif /* LINKID_H_ */
Note: See TracChangeset for help on using the changeset viewer.