2525#include " DeviceManager/DevicePrint.h"
2626#include " DeviceManager/DeviceInput.h"
2727#include " MacroDefinition.h"
28+ #include " commontools.h"
2829
2930// Dtk头文件
3031#include < DSysInfo>
@@ -86,58 +87,6 @@ void DeviceGenerator::generatorComputerDevice()
8687 DeviceManager::instance ()->addComputerDevice (device);
8788}
8889
89- void mergeSortCpuInfoByLogicalID (QList<QMap<QString, QString> > &lsCpu, QList<QMap<QString, QString> > &tmpLst, int begin, int end)
90- {
91- // 合并列表
92- int left_length = (end - begin + 1 ) / 2 ;
93- int left_index = begin;
94- int right_index = begin + left_length;
95- int result_index = begin;
96-
97- // 合并左右区间 左区间未合并结束且右区间未合并结束时
98- while (left_index < begin + left_length && right_index < end + 1 ) {
99- // 左右区间,哪个小先排哪个,下标加1
100- if (lsCpu[left_index][" processor" ].toInt () <= lsCpu[right_index][" processor" ].toInt ())
101- tmpLst[result_index++] = lsCpu[left_index++];
102- else
103- tmpLst[result_index++] = lsCpu[right_index++];
104- }
105-
106- // 合并左区间剩余数据
107- while (left_index < begin + left_length)
108- tmpLst[result_index++] = lsCpu[left_index++];
109-
110- // 合并右区间剩余数据
111- while (right_index < end + 1 )
112- tmpLst[result_index++] = lsCpu[right_index++];
113- }
114-
115- void sortCpuInfoByLogicalID (QList<QMap<QString, QString> > &lsCpu, QList<QMap<QString, QString> > &tmpLst, int begin, int end)
116- {
117- // 列表个数为1,直接返回
118- if (0 == end - begin)
119- return ;
120-
121- // bug 后台获取CPU信息是按照物理CPU,核心,逻辑CPU顺序获取的
122- // 界面上展示顺序混乱实际是按照物理CPU,核心,逻辑CPU顺序展示
123- // 与产品沟通后,按照用户的使用感修改,CPU信息按照逻辑CPU的id从小到大显示
124- // 区间个数为2
125- if (1 == end - begin) {
126- // 前 processor > 后 processor 时交换位置
127- if (lsCpu[begin][" processor" ].toInt () > lsCpu[end][" processor" ].toInt ()) {
128- QMap<QString, QString> tmpMap = lsCpu[begin];
129- lsCpu[begin] = lsCpu[end];
130- lsCpu[end] = tmpMap;
131- }
132- } else {
133- // 区间个数 > 2 递归
134- sortCpuInfoByLogicalID (lsCpu, tmpLst, begin, (end - begin) / 2 + begin);
135- sortCpuInfoByLogicalID (lsCpu, tmpLst, (end - begin + 1 ) / 2 + begin, end);
136- mergeSortCpuInfoByLogicalID (lsCpu, tmpLst, begin, end);
137- lsCpu = tmpLst;
138- }
139- }
140-
14190void DeviceGenerator::generatorCpuDevice ()
14291{
14392 // 生成CPU
@@ -150,7 +99,7 @@ void DeviceGenerator::generatorCpuDevice()
15099
151100 // 按照processor id 从小到大排序
152101 if (lsCpu.size () > 1 )
153- sortCpuInfoByLogicalID (srcLst, tmpLst, 0 , lsCpu.size () - 1 );
102+ CommonTools:: sortCpuInfoByLogicalID (srcLst, tmpLst, 0 , lsCpu.size () - 1 );
154103
155104 // get info from lshw
156105 const QList<QMap<QString, QString> > &lshwCpu = DeviceManager::instance ()->cmdInfo (" lshw_cpu" );
0 commit comments