Ejemplo n.º 1
0
  bool GetCurrentDirectoryX(std::basic_string<Char, Traits, Alloc>& out)
  {
    Blob<Char> buf;
    //TCHAR* tsz = 0;
    DWORD dwRet = 0;
    bool r = false;

    dwRet = GetCurrentDirectoryW(static_cast<DWORD>(buf.Size()), buf.GetBuffer());
    if(dwRet)
    {
      if(dwRet > static_cast<DWORD>(buf.Size()))
      {
        // It needs more space.
        if(buf.Alloc(dwRet+2))
        {
          if(::GetCurrentDirectory(static_cast<DWORD>(buf.Size()), buf.GetBuffer()))
          {
            out = buf.GetBuffer();
            r = true;
          }
        }
      }
      else
      {
        out = buf.GetBuffer();
        r = true;
      }
    }

    return r;
  }
int D3dFlowContextFlowSide::ReceiveBlobFromMapper(
    DDBlobID    blobID, // Identifier of blob to be sent
    int    maxNumBytes,     // max #bytes that can be received
    char * bytes            // pointer to (already allocated) array of bytes
    )
{

    MAPDBG_FUN2("D3dFlowContext::ReceiveBlobFromMapper");

    int numInBytes = 0;

    if ( this->mapperIterator == NULL )
    {
        throw new Exception (true, "ReceiveFromMapper: mapperIterator not set for Flow \"%s\"",
            this->flowIterator == NULL ? "????" : this->flowIterator->name );
    }
    else
    {
        FLOW2D3D->dd->log->Write (Log::DDMAPPER_MINOR, "FLOW \"%s\" WAITS for blob %d from mapper \"%s\"",
                        this->flowIterator->name, blobID, this->mapperIterator->name);
        int incomingBlobID=0;
        Blob * receiveBlob = new Blob(bytes, maxNumBytes);
        this->mapperIterator->Receive(receiveBlob, &incomingBlobID); // ddd-comm: mapper->flow, some blob
        numInBytes = receiveBlob->Size();
        delete receiveBlob;
        if ( incomingBlobID != blobID )
        {
            throw new Exception (true, "D3dFlowContextFlowSide::ReceiveBlobFromMapper: unexpected blobID (%d /= %d)",
                        incomingBlobID, blobID);
        }
        FLOW2D3D->dd->log->Write (Log::DDMAPPER_MINOR, "FLOW \"%s\" RECEIVED blob %d from mapper \"%s\"",
                        this->flowIterator->name, blobID, this->mapperIterator->name);
    }
    return numInBytes;
}
void D3dFlowContextFlowSide::UpdateFlowFromMapper(
    UpdateHeader &updateHeader
    )
{

    MAPDBG_FUN2("D3dFlowContextFlowSide::UpdateFlowFromMapper");

    if (this->memType == Mem_Distributed)
    {
        if ( this->mapperIterator == NULL )
        {
            throw new Exception (true, "UpdateFlowFromMapper: mapperIterator not set for Flow \"%s\"",
                this->flowIterator == NULL ? "????" : this->flowIterator->name );
        }
        else
        {
            //
            // Gather bytes to be sent from Var Info collection
            //

            int headerSize = sizeof(UpdateHeader_STR);

            int maxNumInBytes = this->varInfoColl->GetMaxNumBytes();

            FLOW2D3D->dd->log->Write (Log::DDMAPPER_MINOR, "FLOW \"%s\" WAITS for Update (max %d bytes) from mapper \"%s\"",
                            this->flowIterator->name, maxNumInBytes, this->mapperIterator->name);

            int incomingBlobID=0;
            char * buffer = new char[maxNumInBytes + headerSize];
            Blob * updateInBlob = new Blob(buffer, maxNumInBytes + headerSize);
            this->mapperIterator->Receive(updateInBlob, &incomingBlobID);  // ddd-comm: mapper->flow, update
            int numInBytes = updateInBlob->Size() - headerSize;
            delete updateInBlob;
            if ( incomingBlobID != M2F_Blob_Update )
            {
                throw new Exception (true, "D3dFlowContextFlowSide::UpdateFlowFromMapper: unexpected blobID (%d /= %d)",
                            incomingBlobID, M2F_Blob_Update);
            }

            memcpy(&(updateHeader), buffer, headerSize);

            FLOW2D3D->dd->log->Write (Log::DDMAPPER_MINOR, "FLOW \"%s\" RECEIVED Update from mapper \"%s\" (step %d, #mess %d, numInBytes %d)",
                            this->mapperIterator->name, this->flowIterator->name,
                            updateHeader.nextStep, updateHeader.numMessages, numInBytes
                            );

            //
            // Use Var Info collection to store received values
            //
            int distribGroup = updateHeader.distribGroup;

            this->varInfoColl->PrintGroupInfo(distribGroup);

                        int numReadBytes = this->varInfoColl->BufferGroup(
                                                                        distribGroup, BufferAction_Read,
                                                                        buffer + headerSize, numInBytes);

                        if ( numReadBytes != this->varInfoColl->GetNumBytes(distribGroup) )
                                throw new Exception (true, "FLOW \"%s\" from mapper \"%s\": numReadBytes(%d) != maxNumInBytes(%d)",
                                                        this->flowIterator->name, this->mapperIterator->name,
                                                        numReadBytes, maxNumInBytes );

            delete [] buffer;

        }
    }
}