///////////////////////////////////////////////////////////////////// // client.cpp - Client for Midterm question #1 // // Calls getMap and builds map on client side // // // // Jim Fawcett, CSE775 - Distributed Objects, Spring 2005 // ///////////////////////////////////////////////////////////////////// #include #include #include #include #include #include "_Q1.h" int main() { USES_CONVERSION; CoInitialize(NULL); CComQIPtr pIgetMap; pIgetMap.CoCreateInstance(__uuidof(CgetMap)); if(pIgetMap) { HRESULT hr; CComBSTR path(L".."); hr = pIgetMap->FillMap(path); if(FAILED(hr)) { std::cout << "\n call to FillMap failed\n"; CoUninitialize(); return 1; } ///////////////////////////////////////////////////////////////// // Only this part required for Midterm.Q1 CComBSTR mapData; hr = pIgetMap->GetMap(&mapData); if(FAILED(hr)) { std::cout << "\n call to GetMap failed\n"; CoUninitialize(); return 1; } /////////////////////////////////////////////////////////////// // uncomment this statement to see what GetMap returns // std::wcout << "\n map data\n " << mapData.m_str << "\n\n"; std::wistringstream data(mapData.m_str); std::wstring temp; typedef std::list< std::string> FileList; typedef std::map< std::string, FileList > FileMap; FileMap fm; FileList fl; std::string dirName; while(data.good()) { data >> temp; if(temp == L"Directory:") { data >> temp; std::wcout << L"\n Loading directory: " << temp.c_str(); dirName = W2A(temp.c_str()); fm[dirName] = fl; } else { std::wcout << L"\n adding file: " << temp.c_str(); std::string file = W2A(temp.c_str()); fm[dirName].push_back(file); } } std::cout << "\n\n"; // end of required part ///////////////////////////////////////////////////////////////// } else { std::cout << "\n could not create instance of component\n"; } CoUninitialize(); }