Component.cxx

Go to the documentation of this file.
00001 // -*- mode: C++ -*- 
00002 //
00003 // Copyright (C) 2006 Christian Holm Christensen <cholm@nbi.dk>
00004 //
00005 // This library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public License
00007 // as published by the Free Software Foundation; either version 2.1
00008 // of the License, or (at your option) any later version.
00009 //
00010 // This library is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this library; if not, write to the Free
00017 // Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018 // 02111-1307 USA
00019 //
00025 #include "Component.h"
00026 #include <rcuxx/Altro.h>
00027 #include "SingleValue.h"
00028 #include <rcudb/Server.h>
00029 #include <rcudb/Row.h>
00030 #include <rcudb/Sql.h>
00031 // #include "BlobValue.h"
00032 
00033 //====================================================================
00034 void
00035 RcuConf::Component::Create(RcuDb::Server& s, const std::string& name, 
00036                            Parameter::Where dest, bool isBlob, 
00037                            unsigned int mask) throw(bool)
00038 {
00039   Parameter p(name, dest, isBlob, mask);
00040   if (p.Insert(s)) return;
00041   throw false;
00042 }
00043 
00044 //====================================================================
00045 unsigned int
00046 RcuConf::BusComponent::DoWrite(const Parameter&   p, 
00047                                const SingleValue& v, 
00048                                int board, unsigned int chip, 
00049                                unsigned int channel) 
00050 {
00051   // std::cout << "Processing " << p.Name() << " with value " << v.Values()
00052   // << std::endl;
00053   if (p.IsBlob()) return kInvalidValue;
00054   
00055   // Check if this is a register 
00056   Rcuxx::AltroRegister* reg  = Name2Register(p.Name());
00057   // We return negative error codes for the Rcu++ errors. 
00058   if (reg) {
00059     if (board < 0) { 
00060       if (!reg->IsBroadcastable()) return kInvalidAddress;
00061       reg->SetBroadcast();
00062     }
00063     else
00064       reg->SetAddress(board, chip, channel);
00065     // TODO 
00066     reg->Decode(v.Values());
00067     return - reg->Commit();
00068   }
00069   
00070   // Check if this is a command 
00071   Rcuxx::AltroCommand*  cmd = Name2Command(p.Name());
00072   if (cmd) {
00073     if (board < 0) cmd->SetBroadcast();
00074     else           cmd->SetAddress(board, chip, channel);
00075     // cmd->SetArgument(v.Values());
00076     return - cmd->Commit();
00077   }
00078   return kUnknownParameter;
00079 }
00080 
00081 //____________________________________________________________________
00082 unsigned int
00083 RcuConf::BusComponent::DoRead(const Parameter&   p, 
00084                               SingleValue&       v,
00085                               int board, unsigned int chip, 
00086                               unsigned int channel) 
00087 {
00088   
00089   if (p.IsBlob()) return kInvalidValue;
00090   
00091   // Check if this is a register 
00092   Rcuxx::AltroRegister* reg  = Name2Register(p.Name());
00093   // We return negative error codes for the Rcu++ errors. 
00094   if (reg) {
00095     if (board < 0 &&  !reg->IsBroadcastable()) return kInvalidAddress;
00096     unsigned ret = reg->Update(); // Should we do this?
00097     v.Set(reg->Encode()); 
00098     return - ret;
00099   }
00100   
00101   // Check if this is a command 
00102   Rcuxx::AltroCommand*  cmd = Name2Command(p.Name());
00103   if (cmd) {
00104     // v = cmd->Argument();
00105     return kSuccess;
00106   }
00107   return kUnknownParameter;
00108 }
00109 
00110 //____________________________________________________________________
00111 //
00112 // EOF
00113 //
Top of page Last update Fri Apr 27 01:54:15 2007
Copyright © 2004 Christian Holm Created by DoxyGen 1.3.5