00001 /*************************************************************************** 00002 l1394_transaction.h - description 00003 ------------------- 00004 begin : Sun Jul 1 2001 00005 copyright : (C) 2001-2004 by Michael Repplinger 00006 email : repplix@studcs.uni-sb.de 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 #ifndef L1394_TRANSACTION_H 00019 #define L1394_TRANSACTION_H 00020 #include <netinet/in.h> 00021 #include <sys/poll.h> 00022 #include <sys/types.h> 00023 #include <sys/time.h> 00024 #include <unistd.h> 00025 #include <string> 00026 #include "libraw1394/csr.h" 00027 #include "libraw1394/raw1394.h" 00028 00029 #include "l1394_quadlet.h" 00030 #include "l1394_qarray.h" 00031 #include "l1394_resource.h" 00032 #include "l1394_message.h" 00033 00034 namespace L1394 { 00035 namespace internal { 00036 00037 00038 /** \class Transaction 00039 * \brief This class is a wrapper class for the libraw1394 library. 00040 * 00041 * It provides methods for the FireWire specific transactions (read, write and lock) 00042 * and AV/C specific transactions (send). 00043 * 00044 *@author Michael Repplinger 00045 */ 00046 class Transaction { 00047 public: 00048 00049 /*! \name Transaction constructor 00050 * These functions creates a Transaction object. 00051 */ 00052 //@{ 00053 /*! \fn Transaction(raw1394handle_t) 00054 * \brief Constructor 00055 */ 00056 Transaction(raw1394handle_t); 00057 00058 00059 /*! \fn ~Transaction() 00060 * \brief Destructor 00061 */ 00062 ~Transaction(); 00063 //@} 00064 00065 00066 /*! \name Transactions 00067 * These methods are wrapper for the libraw functions. 00068 */ 00069 //@{ 00070 /*! \fn read(const u_int64_t address, Quadlet* quadlet, const u_int32_t node_id) const 00071 * \brief This method reads 4 bytes from CsrRom of a specific node and return the value. 00072 * \param address : u_int64_t integer value for the address of CSR 00073 * \param node_number : send to node with node_number 00074 * \param quadlet : pointer to the Quadlet to store the value. 00075 * \return Quadlet : value stored in this address 00076 */ 00077 int read(const u_int64_t address, Quadlet* q, const u_int32_t node_id) const; 00078 00079 00080 /*! \fn write(const u_int64_t address, const Quadlet& data, const u_int32_t node_id) const 00081 * \brief This method writes 4 bytes to CsrRom of a specific node 00082 * \param address : u_int64_t value for the CSR-address 00083 * \param data : Quadlet with the data that should be written to CSR-address 00084 * \param node_number : write to node with this actual node_number 00085 */ 00086 int write(const u_int64_t address, const Quadlet& data, const u_int32_t node_id ) const ; 00087 00088 00089 /*! \fn lock (const u_int64_t address, const Quadlet& data, const unsigned int extcode,const Quadlet& argument, Quadlet* result, const u_int32_t node_id) const 00090 * \brief This method realizes an atomic transaction on the FireWire bus. 00091 * 00092 * An atomic transaction means, that no node can access the address during the lock operation. 00093 * \param address : u_int64_t value for the CSR-address 00094 * \param data : The data Quadlet defines the value that should be executed on the address 00095 * \param extcode : The extension code defines the type of lock operation. 00096 * \param argument : The argument value is compared with the actual address value and depending on the extension code a operation with the data value is executed. 00097 * \param result : If a value is returned, it is stored in result 00098 * \param node_id : current node-id of the node 00099 * \return int: L1394_FAILED, if the transaction fails, else L1394_SUCCESS. 00100 */ 00101 int lock(const u_int64_t address,const Quadlet& data,const unsigned int extcode, const Quadlet& argument, Quadlet* result, const u_int32_t node_id) const ; 00102 00103 00104 /*! \fn send(const Quadlet& command, const u_int32_t node_id) const 00105 * \brief This method sends a Quadlet (4 bytes) to the node with current node_ide. 00106 * \param command : The Quadlet to send. 00107 * \param node_id : current node_id of the node 00108 * \return Quadlet : The Quadlet with response code. 00109 */ 00110 Quadlet send(const Quadlet& command, const u_int32_t node_id) const; 00111 00112 00113 /*! \fn send(const QArray& command, const u_int32_t node_id) const 00114 * \brief This method sends an QArray to a node. 00115 * \param QArray with the extended command 00116 * \param node_id : current node_id of the node 00117 * \return QArray with the response code. 00118 */ 00119 QArray send(const QArray& command, const u_int32_t node_id) const; 00120 //@} 00121 00122 /*! \fn setSafeMode(bool b, int delay) 00123 * \brief This method enables/disables the safe mode for asynchrone transactions. 00124 * 00125 * If you enable the safemode a delay between every transaction is enabled. 00126 */ 00127 static void setSafeMode(bool b, int d) {safe_mode = b; delay_value = d;} 00128 00129 //! delay for msecs i 00130 static void delay(int i); 00131 00132 private: 00133 00134 static int L1394FcpHandler(raw1394handle_t , nodeid_t nodeid, int , size_t length, unsigned char *data); 00135 00136 static bool safe_mode; 00137 static int delay_value; 00138 00139 static QArray* response_block; 00140 00141 raw1394handle_t default_handle; 00142 //static int my_tag_handler(raw1394handle_t handle, unsigned long tag, 00143 // raw1394_errcode_t errcode); 00144 00145 }; 00146 00147 } //end namespace internal 00148 } //end namespace L1394 00149 #endif