* RefreshData -- This method is called by Microsoft Excel to get new data. * This method call only takes place after being notified by the real-time * data server that there is new data. * Parameters: TopicCount -- filled with the count of topics in the safearray * parrayOut -- two-dimensional safearray. First dimension * contains the list of topic IDs.
| 519 | * E_FAIL |
| 520 | ******************************************************************************/ |
| 521 | STDMETHODIMP RTDServer::RefreshData( long *TopicCount, |
| 522 | SAFEARRAY **parrayOut) |
| 523 | { |
| 524 | //Check the arguments first |
| 525 | if ((TopicCount == NULL) || (parrayOut == NULL) || (*parrayOut != NULL)){ |
| 526 | // Bad pointer |
| 527 | return E_POINTER; |
| 528 | } |
| 529 | |
| 530 | HRESULT hr = S_OK; |
| 531 | |
| 532 | //Set the TopicCount |
| 533 | *TopicCount = static_cast<long>(m_pTopicList.size()); |
| 534 | |
| 535 | |
| 536 | SAFEARRAYBOUND bounds[2]; |
| 537 | |
| 538 | //Build the safe-array values we want to insert |
| 539 | bounds[0].cElements = 2; |
| 540 | bounds[0].lLbound = 0; |
| 541 | bounds[1].cElements = *TopicCount; |
| 542 | bounds[1].lLbound = 0; |
| 543 | *parrayOut = SafeArrayCreate(VT_VARIANT, 2, bounds); |
| 544 | |
| 545 | int i = 0; |
| 546 | for (TopicList::const_iterator iTopic = m_pTopicList.begin(); |
| 547 | iTopic != m_pTopicList.end(); ++iTopic, ++i) { |
| 548 | std::stringstream topicValue; |
| 549 | long index[2]; |
| 550 | index[0] = 0; |
| 551 | index[1] = i; |
| 552 | |
| 553 | VARIANT value; |
| 554 | VariantInit(&value); |
| 555 | value.vt = VT_I4; |
| 556 | value.lVal = iTopic->first; |
| 557 | SafeArrayPutElement(*parrayOut, index, &value); |
| 558 | |
| 559 | index[0] = 1; |
| 560 | index[1] = i; |
| 561 | |
| 562 | const std::string& topicName = iTopic->second.name; |
| 563 | if (topicName != MONITOR_HEARTBEAT) { |
| 564 | Monitor::RTDMonitor* monitor = getMonitor(iTopic->second); |
| 565 | |
| 566 | if (topicName == MONITOR_COLUMN_COUNT) { |
| 567 | topicValue << (monitor ? monitor->getColumnCount() : 0); |
| 568 | } else if (topicName == MONITOR_IS_NODE_VALID) { |
| 569 | bool isNodeValid = (monitor ? monitor->isNodeValid(iTopic->second.parameters[0]) : false); |
| 570 | topicValue << (isNodeValid ? "True" : "False"); |
| 571 | |
| 572 | } else if (topicName == MONITOR_NODE_VALUE) { |
| 573 | int index = atoi(iTopic->second.parameters[1].c_str()); |
| 574 | |
| 575 | if (monitor == NULL) { |
| 576 | topicValue << "#Error: unable to find monitor with id: " << iTopic->second.monitorId; |
| 577 | } else { |
| 578 | topicValue << monitor->getNodeValue(iTopic->second.parameters[0], index); |
nothing calls this directly
no test coverage detected