Line 1... |
Line 1... |
/**
|
/*
|
* @file
|
* Copyright 2018 Sergey Khabarov, sergeykhbr@gmail.com
|
* @copyright Copyright 2016 GNSS Sensor Ltd. All right reserved.
|
*
|
* @author Sergey Khabarov - sergeykhbr@gmail.com
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
* @brief Core Service interface declaration.
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
*/
|
*/
|
|
|
#ifndef __DEBUGGER_SERVICE_H__
|
#ifndef __DEBUGGER_COMMON_ISERVICE_H__
|
#define __DEBUGGER_SERVICE_H__
|
#define __DEBUGGER_COMMON_ISERVICE_H__
|
|
|
#include "iface.h"
|
#include <iface.h>
|
#include "attribute.h"
|
#include <attribute.h>
|
#include "api_utils.h"
|
#include <api_utils.h>
|
|
#include "coreservices/imemop.h"
|
|
|
namespace debugger {
|
namespace debugger {
|
|
|
static const char *const IFACE_SERVICE = "IService";
|
static const char *const IFACE_SERVICE = "IService";
|
|
|
class IService : public IFace {
|
class IService : public IFace {
|
public:
|
public:
|
IService(const char *obj_name)
|
explicit IService(const char *obj_name) : IFace(IFACE_SERVICE) {
|
: IFace(IFACE_SERVICE) {
|
|
listInterfaces_ = AttributeType(Attr_List);
|
listInterfaces_ = AttributeType(Attr_List);
|
listAttributes_ = AttributeType(Attr_List);
|
listAttributes_ = AttributeType(Attr_List);
|
|
listPorts_ = AttributeType(Attr_List);
|
registerInterface(static_cast<IService *>(this));
|
registerInterface(static_cast<IService *>(this));
|
registerAttribute("LogLevel", &logLevel_);
|
registerAttribute("LogLevel", &logLevel_);
|
obj_name_ = obj_name;
|
obj_name_.make_string(obj_name);
|
logLevel_.make_int64(LOG_ERROR);
|
logLevel_.make_int64(LOG_ERROR);
|
}
|
}
|
virtual ~IService() {}
|
virtual ~IService() {
|
|
// @warning: NEED to unregister attribute from class destructor
|
|
/*for (unsigned i = 0; i < listAttributes_.size(); i++) {
|
|
IAttribute *iattr = static_cast<IAttribute *>(
|
|
listAttributes_[i].to_iface());
|
|
iattr->freeAttrName();
|
|
iattr->freeAttrDescription();
|
|
}*/
|
|
}
|
|
|
virtual void initService(const AttributeType *args) {
|
virtual void initService(const AttributeType *args) {
|
if (!args || !args->is_list()) {
|
if (!args || !args->is_list()) {
|
return;
|
return;
|
}
|
}
|
Line 45... |
Line 63... |
RISCV_error("Attribute '%s' not found", item[0u].to_string());
|
RISCV_error("Attribute '%s' not found", item[0u].to_string());
|
continue;
|
continue;
|
}
|
}
|
(*cur_attr) = item[1];
|
(*cur_attr) = item[1];
|
if (item.size() >= 3 && item[2].is_string()) {
|
if (item.size() >= 3 && item[2].is_string()) {
|
static_cast<IAttribute *>(cur_attr)->setAttrDescription(
|
static_cast<IAttribute *>(cur_attr)->allocAttrDescription(
|
item[2].to_string());
|
item[2].to_string());
|
}
|
}
|
}
|
}
|
}
|
}
|
|
|
Line 57... |
Line 75... |
virtual void predeleteService() {}
|
virtual void predeleteService() {}
|
|
|
virtual void registerInterface(IFace *iface) {
|
virtual void registerInterface(IFace *iface) {
|
AttributeType item(iface);
|
AttributeType item(iface);
|
listInterfaces_.add_to_list(&item);
|
listInterfaces_.add_to_list(&item);
|
|
if (strcmp(iface->getFaceName(), IFACE_MEMORY_OPERATION) == 0) {
|
|
IMemoryOperation *imemop = static_cast<IMemoryOperation *>(iface);
|
|
registerAttribute("MapList", &imemop->listMap_);
|
|
registerAttribute("BaseAddress", &imemop->baseAddress_);
|
|
registerAttribute("Length", &imemop->length_);
|
|
registerAttribute("Priority", &imemop->priority_);
|
|
}
|
|
}
|
|
virtual void registerPortInterface(const char *portname, IFace *iface) {
|
|
AttributeType item;
|
|
item.make_list(2);
|
|
item[0u].make_string(portname);
|
|
item[1].make_iface(iface);
|
|
listPorts_.add_to_list(&item);
|
}
|
}
|
|
|
virtual void unregisterInterface(IFace *iface) {
|
virtual void unregisterInterface(IFace *iface) {
|
for (unsigned i = 0; i < listInterfaces_.size(); i++) {
|
for (unsigned i = 0; i < listInterfaces_.size(); i++) {
|
if (listInterfaces_[i].to_iface() == iface) {
|
if (listInterfaces_[i].to_iface() == iface) {
|
Line 79... |
Line 111... |
}
|
}
|
}
|
}
|
return NULL;
|
return NULL;
|
}
|
}
|
|
|
|
virtual IFace *getPortInterface(const char *portname,
|
|
const char *facename) {
|
|
IFace *tmp;
|
|
for (unsigned i = 0; i < listPorts_.size(); i++) {
|
|
AttributeType &item = listPorts_[i];
|
|
if (!item[0u].is_equal(portname)) {
|
|
continue;
|
|
}
|
|
tmp = item[1].to_iface();
|
|
if (strcmp(facename, tmp->getFaceName()) == 0) {
|
|
return tmp;
|
|
}
|
|
}
|
|
return NULL;
|
|
}
|
|
|
virtual void registerAttribute(const char *name, IAttribute *iface) {
|
virtual void registerAttribute(const char *name, IAttribute *iface) {
|
AttributeType item(iface);
|
AttributeType item(iface);
|
iface->setAttrName(name);
|
iface->allocAttrName(name);
|
listAttributes_.add_to_list(&item);
|
listAttributes_.add_to_list(&item);
|
}
|
}
|
|
|
virtual IAttribute *getAttribute(const char *name) {
|
virtual IAttribute *getAttribute(const char *name) {
|
IAttribute *tmp;
|
IAttribute *tmp;
|
Line 96... |
Line 144... |
}
|
}
|
}
|
}
|
return NULL;
|
return NULL;
|
}
|
}
|
|
|
virtual const char *getObjName() { return obj_name_; }
|
virtual const char *getObjName() { return obj_name_.to_string(); }
|
|
|
virtual AttributeType getConfiguration() {
|
virtual AttributeType getConfiguration() {
|
AttributeType ret(Attr_Dict);
|
AttributeType ret(Attr_Dict);
|
ret["Name"] = AttributeType(getObjName());
|
ret["Name"] = AttributeType(getObjName());
|
ret["Attr"] = AttributeType(Attr_List);
|
ret["Attr"] = AttributeType(Attr_List);
|
Line 117... |
Line 165... |
return ret;
|
return ret;
|
}
|
}
|
|
|
protected:
|
protected:
|
AttributeType listInterfaces_;
|
AttributeType listInterfaces_;
|
|
AttributeType listPorts_; // [['portname',iface],*]
|
AttributeType listAttributes_;
|
AttributeType listAttributes_;
|
AttributeType logLevel_;
|
AttributeType logLevel_;
|
const char *obj_name_;
|
AttributeType obj_name_;
|
};
|
};
|
|
|
} // namespace debugger
|
} // namespace debugger
|
|
|
#endif // __DEBUGGER_SERVICE_H__
|
#endif // __DEBUGGER_COMMON_ISERVICE_H__
|
|
|
No newline at end of file
|
No newline at end of file
|