Exemplo n.º 1
0
void ProtocolChooserWidget::loadImpl()
{
	clear();
	ConfigGroup group = Config().group("protocols");
	QVariantMap selected = group.value("list", QVariantMap());
	QStandardItem *parent_item = m_model->invisibleRootItem();

	ExtensionInfoList exts = extensionList();
	for (int i = 0; i < exts.size(); i++) {
		const ExtensionInfo &info = exts.at(i);
		const QMetaObject *meta = info.generator()->metaObject();
		QString name = QString::fromLatin1(MetaObjectBuilder::info(meta, "Protocol"));
		if (name.isEmpty())
			continue;

		if (!m_protocol_items.contains(name)) {
			ServiceItem *item = new ServiceItem(Icon("applications-system") ,name);
			item->setData(true,ServiceItem::ExclusiveRole);
			parent_item->appendRow(item);
			m_protocol_items.insert(name,item);
		}
		QIcon icon = Icon("applications-system");
		//TODO Make normal names for the implementation of protocols
		ServiceItem *item = new ServiceItem(icon,info.name());
		//ServiceItem *item = new ServiceItem(icon,info.name());

		item->setToolTip(ServiceChooser::html(info));
		item->setCheckable(true);
		item->setData(info.description().toString(),DescriptionRole);
		if (selected.value(name).toString() == ServiceChooser::className(info))
			item->setCheckState(Qt::Checked);
		item->setData(ServiceChooser::className(info),ServiceItem::ExtentionInfoRole);
		m_protocol_items.value(name)->appendRow(item);
	}
}
Exemplo n.º 2
0
void PluginChoooserWidget::loadImpl()
{
	clear();
	Config group = Config().group("plugins/list");
	QStandardItem *parent_item = m_model->invisibleRootItem();

    QList<QWeakPointer<Plugin> > plugins = pluginsList();
	QStringList helper;
    for (int i = 0; i < plugins.size(); i++) {
        const PluginInfo &info = plugins.at(i).data()->info();
        QLatin1String class_name(plugins.at(i).data()->metaObject()->className());
        if (!m_plugin_items.contains(info.name())) {
			QIcon icon = info.icon();
			if (icon.isNull() || !icon.availableSizes().count())
				icon = Icon("applications-system");
			QString name = info.name();
			int index = qLowerBound(helper, name) - helper.constBegin();
			helper.insert(index, name);
			ServiceItem *item = new ServiceItem(icon, name);
			item->setToolTip(html(info));
			item->setCheckable(true);
			item->setData(true,ServiceItem::ExclusiveRole);
			item->setData(info.description().toString(), DescriptionRole);
			item->setCheckState((group.value(class_name, true) ? Qt::Checked : Qt::Unchecked));
			parent_item->insertRow(index, item);
			m_plugin_items.insert(class_name, item);
            m_plugins.insert(class_name, plugins.at(i).data());
		}
	}
}
Exemplo n.º 3
0
void ServiceChoooserWidget::loadImpl()
{
	clear();
	ConfigGroup group = Config().group("services");
	QVariantMap selected = group.value("list", QVariantMap());
	QStandardItem *parent_item = m_model->invisibleRootItem();

	ExtensionInfoList exts = extensionList();
	QStringList helper;
	for (int i = 0; i < exts.size(); ++i) {
		const ExtensionInfo &info = exts.at(i);
		const char *serviceName = MetaObjectBuilder::info(info.generator()->metaObject(), "Service");

		if (serviceName && *serviceName) {
			if (!m_service_items.contains(serviceName)) {
				QString localizedName = QT_TRANSLATE_NOOP("Service",serviceName).toString();
				int index = qLowerBound(helper, localizedName) - helper.constBegin();
				helper.insert(index, localizedName);
				ServiceItem *item = new ServiceItem(Icon(serviceIcon(serviceName)),localizedName);
				item->setData(true,ServiceItem::ExclusiveRole);
				parent_item->insertRow(index, item);
				m_service_items.insert(serviceName,item);
			}
			QIcon icon = !info.icon().name().isEmpty() ?
						 info.icon() :
						 Icon("applications-system");
			ServiceItem *item = new ServiceItem(icon,info.name());

			item->setToolTip(ServiceChoooser::html(info));
			item->setCheckable(true);
			item->setData(info.description().toString(),DescriptionRole);
			if (selected.value(serviceName).toString() == ServiceChoooser::className(info))
				item->setCheckState(Qt::Checked);
			item->setData(qVariantFromValue(info), ServiceItem::ExtentionInfoRole);

			m_service_items.value(serviceName)->appendRow(item);
		}
	}
}
Exemplo n.º 4
0
int RouteTableImpl::load(const char* buff, int data_len)
{

    m_lock.lock();
    unordered_map<INSTANCE_ID_TYPE, ServiceItem>  new_service_map;
    vector< vector<ServiceItem> > new_service_list;
    vector< vector<ServiceItem> > new_local_service_list;
    vector< vector<ServiceItem> > new_local_host_service_list;
 
    new_service_list.resize(m_service_count);
    new_local_service_list.resize(m_service_count);
    new_local_host_service_list.resize(m_service_count);
 
    int r = get_local_ip_addr(m_local_ip_set);
    if (r != 0)
    {
        LOG_ERROR("Failed to get the local ip addr set");
        m_lock.unlock();
        return -1;
    }   
    
    unordered_set<std::string>::iterator it;
    for (it = m_local_ip_set.begin(); it != m_local_ip_set.end(); ++it)
    {
        LOG_DEBUG("local ip: " << *it);
    }
    
    std::string content(buff, data_len);
    std::vector<std::string> lines;
    split_str(content, lines, '\n');
    string current_service;
    ServiceItem item;
    for (size_t i=0; i<lines.size(); ++i)
    {
        current_service.clear();

        
        std::string line = trim(lines[i]);
        if (line.size() == 0 || line[0] == '#')
        {
            continue;
        }
        

        vector<string> tmp;
        split_str(line, tmp, '=', 1);
        
        size_t pos;
        pos = tmp[0].rfind("service_type");
        if (pos != string::npos)
        {
            //Find the begining of the service info
            item.instance_name = tmp[0].substr(0,pos-1);
            item.service_type = atoi(tmp[1].c_str());
            item.update_service_seq();
            LOG_DEBUG("instance_name = " << item.instance_name
                << ", service_seq=" << item.service_seq
                << ", service_type:" << item.service_type);
                
            continue;
        }
        

        //Find the instance_id
        pos = tmp[0].rfind("instance_id");
        if (pos != string::npos)
        {
            ServiceInstanceId id;
            if (id.set_by_str(tmp[1]) != 0)
            {
                LOG_ERROR("Failed to parse instance_id. Id:" << tmp[1]);
                m_lock.unlock();
                return -1;                
            }
            item.instance_id = id.get_value();
            LOG_DEBUG("instance_id:" << tmp[1].c_str()
                << ", digital form:"  << item.instance_id);
            continue;
        }
        
        //Find the tcp_addr
        pos = tmp[0].rfind("tcp_addr");
        if (pos != string::npos)
        {
            std::vector<std::string> tcp_addr_list;
            split_str(tmp[1], tcp_addr_list, ',');
            if (tcp_addr_list.size() <= 0)
            {
                LOG_ERROR("No tcp_addr for this service:" << item.instance_name);
            }
            std::pair<std::string, uint16_t> tcp_addr;
            for (size_t i=0; i<tcp_addr_list.size(); ++i)
            {
                str_to_tcp_addr(tcp_addr_list[i], tcp_addr);
                item.tcp_addr_list.push_back(tcp_addr);
                LOG_DEBUG(item.instance_name << ",ip:" 
                    << tcp_addr.first << ", port:" 
                    << tcp_addr.second);
            }
            
            //Find the group_id
            item.group_id = ServiceGroupingTable::instance()->get_group_id(item.service_type, item.tcp_addr_list[0].first);
            LOG_DEBUG("group_id:" << item.group_id);
            continue;            
        } 
        
        //Find the ipc_addr
        pos = tmp[0].rfind("ipc_addr");
        if (pos != string::npos)
        {
            split_str(tmp[1], item.ipc_addr_list, ',');           
            //LOG_DEBUG("ipc_addr:" << item.ipc_addr);
            continue;
        } 
        
        
        //Find the state
        pos = tmp[0].rfind("state");
        if (pos != string::npos)
        {           
            item.state = atoi(tmp[1].c_str());
            LOG_DEBUG("state:" << item.state);      
            
            if (update_service_map(item, new_service_map) != 0)
            {
                m_lock.unlock();
                return -1;
            }
            
            //Update m_serv_instance_map
            update_service_list(item, new_service_list);     
    
            //Update m_serv_addr_map
            //update_addr_map(item);             
            update_local_service_list(item, new_local_service_list);
            update_local_host_service_list(item, new_local_host_service_list);
            item.reset();              
        } 
        
        
 

    }
    
    if (new_service_list.size() > 0 && new_local_service_list.size() > 0
        && new_local_host_service_list.size() > 0)
    {
        new_service_list.swap(m_service_list);
        new_local_service_list.swap(m_local_service_list);
        new_local_host_service_list.swap(m_local_host_service_list);
        new_service_map.swap(m_service_map);
        update_group_list();
        LOG_INFO("RouteTable has been updated successfully!");
    }
    else
    {
        LOG_WARN("No valid content for RouteTable to load"
            << ". new_service_list.size: " << new_service_list.size()
            << ". new_local_service_list.size:" << new_local_service_list.size()
            << ". new_local_host_service_list:" << new_local_host_service_list.size()); 
    }
          
    m_lock.unlock();
    
    return 0;
}