Beispiel #1
0
void CLogView::Log(LogFacility logType, BSTR bsSource, BSTR bsModuleID, SAFEARRAY* pVals)
{
  LogIntro(logType, bsSource, bsModuleID);

  ATLASSERT(0 == pVals->rgsabound[0].lLbound);
  VARIANT* pVariants = (VARIANT*)pVals->pvData;
  for(ULONG n = 0; n < pVals->rgsabound[0].cElements; n++)
  {
    LogVariant(pVariants[pVals->rgsabound[0].cElements - n - 1]);
    AppendText(_T(" "));
  }

  LogExtro();
}
Beispiel #2
0
void CLogView::Log(LogFacility logType, BSTR bsSource, BSTR bsModuleID, VARIANT vtValue)
{
  LogIntro(logType, bsSource, bsModuleID);
  LogVariant(vtValue);
  LogExtro();
}
Beispiel #3
0
void LogViewRE::Log(LogFacility logType, LPCWSTR aName, SAFEARRAY* pVals, LPDISPATCH pOptions)
{
  LogIntro(logType, aName);

  ATLASSERT(0 == pVals->rgsabound[0].lLbound);
  VARIANT* pVariants = (VARIANT*)pVals->pvData;

  // see if we can do a printf
  ULONG valueCount = pVals->rgsabound[0].cElements;
  ULONG currentValueIndex = 0;

  if ((valueCount > 1) && (VT_BSTR == pVariants[0].vt)) {
    ++currentValueIndex;
    CStringW sIn(pVariants[0].bstrVal), sOut;
    int pos = sIn.Find(L'%');
    int posLast = 0;
    int sInLength = sIn.GetLength();
    while((-1 != pos) && (pos < sInLength-1) && (currentValueIndex < valueCount)) {
      // add everything before
      sOut += sIn.Mid(posLast, (pos - posLast));
      ++pos;
      wchar_t format = sIn[pos];
      CComVariant vt(pVariants[currentValueIndex]);
      HRESULT hr = E_FAIL;
      switch(format) {
        case L's':
          // a string: change to string type and log as it is
          hr = vt.ChangeType(VT_BSTR);
          if (SUCCEEDED(hr)) {
            sOut += vt.bstrVal;
          }
          ++currentValueIndex;
          ++pos;
          break;
        case L'd':
        case L'i':
          // an integer number
          // check for type, set "undefined" if empty, "NaN" if can't be converted to a number
          {
            CStringW s;
            switch (vt.vt) {
              case VT_I1:
              case VT_I2:
              case VT_I4:
              case VT_INT:
                s.Format(L"%i", vt.lVal);
                break;
              case VT_UI1:
              case VT_UI2:
              case VT_UI4:
              case VT_UINT:
                s.Format(L"%u", vt.ulVal);
                break;
              case VT_EMPTY:
                s = L"-undefined-";
                break;
              default:
                if (SUCCEEDED(vt.ChangeType(VT_UI4))) {
                  s.Format(L"%u", vt.ulVal);
                }
                else if (SUCCEEDED(vt.ChangeType(VT_I4))) {
                  s.Format(L"%u", vt.lVal);
                }
                else {
                  s = L"NaN";
                }
                break;
            }
            ++currentValueIndex;
            sOut += s;
          }
          ++pos;
          break;
        case L'f':
          // a float number
          // check for type, set "undefined" if empty, "NaN" if can't be converted to a number
          {
            CStringW s;
            switch (vt.vt) {
              case VT_R4:
                s.Format(L"%f", vt.fltVal);
                break;
              case VT_R8:
                s.Format(L"%f", vt.dblVal);
                break;
              case VT_EMPTY:
                s = L"-undefined-";
                break;
              default:
                if (SUCCEEDED(vt.ChangeType(VT_R8))) {
                  s.Format(L"%f", vt.dblVal);
                }
                else {
                  s = L"NaN";
                }
                break;
            }
            ++currentValueIndex;
            sOut += s;
          }
          ++pos;
          break;
        case L'o':
          // an object
          // check for type, set "undefined" if empty, "NaO" if can't be converted to string representation
          if (VT_DISPATCH == vt.vt) {
            CStringW s, s2;
            s2.Format(L"[Object at 0x%%0%ix]", sizeof(vt.pdispVal) * 2);
            s.Format(s2, (IUnknown*)(vt.pdispVal));
            sOut += s;
          }
          else if (VT_EMPTY == vt.vt) {
            sOut += L"-undefined-";
          }
          else if (SUCCEEDED(vt.ChangeType(VT_BSTR))) {
            sOut += vt.bstrVal;
          }
          else {
            sOut += L"NaO";
          }
          ++currentValueIndex;
          ++pos;
          break;
        default:
          // all other cases: not a format spec, take it as it is
          sOut += L'%';
          sOut += format;
          ++pos;
          break;
      }
      posLast = pos;
      pos = sIn.Find(L'%', pos);
    }
    // append the rest
    sOut += sIn.Mid(posLast);
    LogVariant(CComVariant(sOut));
    AppendText(_T(" "));
  }

  // log all the rest
  for(ULONG n = currentValueIndex; n < pVals->rgsabound[0].cElements; n++)
  {
    LogVariant(pVariants[n]);
    AppendText(_T(" "));
  }

  LogExtro();
}
Beispiel #4
0
void LogViewRE::Log(LogFacility logType, LPCWSTR aName, VARIANT vtValue, LPDISPATCH pOptions)
{
  LogIntro(logType, aName);
  LogVariant(vtValue);
  LogExtro();
}
Beispiel #5
0
static int LogField(d_String* str, adbus_Iterator* i)
{
    const adbus_Bool*     b;
    const uint8_t*        u8;
    const int16_t*        i16;
    const uint16_t*       u16;
    const int32_t*        i32;
    const uint32_t*       u32;
    const int64_t*        i64;
    const uint64_t*       u64;
    const double*         d;
    const char*     string;
    size_t          size;

    switch (*i->sig)
    {
    case ADBUS_BOOLEAN:
        if (adbus_iter_bool(i, &b))
            return -1;
        ds_cat_f(str, "%s", *b ? "true" : "false");
        break;
    case ADBUS_UINT8:
        if (adbus_iter_u8(i, &u8))
            return -1;
        ds_cat_f(str, "%d", (int) *u8);
        break;
    case ADBUS_INT16:
        if (adbus_iter_i16(i, &i16))
            return -1;
        ds_cat_f(str, "%d", (int) *i16);
        break;
    case ADBUS_UINT16:
        if (adbus_iter_u16(i, &u16))
            return -1;
        ds_cat_f(str, "%d", (int) *u16);
        break;
    case ADBUS_INT32:
        if (adbus_iter_i32(i, &i32))
            return -1;
        ds_cat_f(str, "%d", (int) *i32);
        break;
    case ADBUS_UINT32:
        if (adbus_iter_u32(i, &u32))
            return -1;
        ds_cat_f(str, "%u", (unsigned int) *u32);
        break;
    case ADBUS_INT64:
        if (adbus_iter_i64(i, &i64))
            return -1;
        ds_cat_f(str, "%lld", (long long int) *i64);
        break;
    case ADBUS_UINT64:
        if (adbus_iter_u64(i, &u64))
            return -1;
        ds_cat_f(str, "%llu", (long long unsigned int) *u64);
        break;
    case ADBUS_DOUBLE:
        if (adbus_iter_double(i, &d))
            return -1;
        ds_cat_f(str, "%.15g", *d);
        break;
    case ADBUS_STRING:
        if (adbus_iter_string(i, &string, &size))
            return -1;
        ds_cat_f(str, "\"%*s\"", size, string);
        break;
    case ADBUS_OBJECT_PATH:
        if (adbus_iter_objectpath(i, &string, &size))
            return -1;
        ds_cat_f(str, "\"%*s\"", size, string);
        break;
    case ADBUS_SIGNATURE:
        if (adbus_iter_signature(i, &string, &size))
            return -1;
        ds_cat_f(str, "\"%*s\"", size, string);
        break;
    case ADBUS_DICTENTRY_BEGIN:
        if (LogField(str, i))
            return -1;
        ds_cat_f(str, " = ");
        if (LogField(str, i))
            return -1;
        if (*i->sig != ADBUS_DICTENTRY_END)
            return -1;
        break;
    case ADBUS_ARRAY_BEGIN:
        return LogArray(str, i);
    case ADBUS_STRUCT_BEGIN:
        return LogStruct(str, i);
    case ADBUS_VARIANT_BEGIN:
        return LogVariant(str, i);
    default:
        assert(0);
        return -1;
    }
    return 0;
}