Пример #1
0
/****************************************************************************
 * Main function call. Invoke all test cases from here.                     *
 ****************************************************************************/
int
main (int argc, char *argv[])
{
  (void)argc;
  (void)argv;

  init ();

  hdr ("Starting to run the test cases.");

  test_emod ();

  test_mmod ();

  test_fmod ();

  test_lmod ();

  test_omod ();

  test_smod ();

  test_tmod ();

  hdr ("Test case run finished execution.");

  fin ();

  return 0;
}
Пример #2
0
static void check_sender()
{
	const char *h=hdr("reply-to");
	struct rfc822t *t;
	struct rfc822a *a;

	if (!h || !*h)
		h=hdr("from");

	if (!h || !*h)
		exit(0);

	t=rfc822t_alloc_new(h, NULL, NULL);

	if (!t || !(a=rfc822a_alloc(t)))
	{
		perror("malloc");
		exit(EX_TEMPFAIL);
	}

	if (a->naddrs <= 0)
		exit (0);
	sender=rfc822_getaddr(a, 0);
	rfc822a_free(a);
	rfc822t_free(t);

	if (!sender || !*sender)
		exit(0);
}
Пример #3
0
static void check_dsn()
{
	static const char ct[]="multipart/report;";

	const char *p=hdr("content-type");

	if (strncasecmp(p, ct, sizeof(ct)-1) == 0)
		exit(0);

	p=hdr("precedence");

	if (strncasecmp(p, "junk", 4) == 0 ||
	    strncasecmp(p, "bulk", 4) == 0 ||
	    strncasecmp(p, "list", 4) == 0)
		exit(0);	/* Just in case */

	p=hdr("auto-submitted");

	if (*p && strcmp(p, "no"))
		exit(0);

	p=hdr("list-id");

	if (*p)
		exit(0);
}
Пример #4
0
void
test_emod (void)
{

  int err;

  hdr ("Testing of emod module started");

  err = 10;

  retVal = errno2EC (err);
  EXEC_TSTCASE (&tstCase, "Err = 10 in errno2EC", (retVal == -10), retVal,
		"Errno not proper", 0);

  retVal = strcmp (strerror (err), ec2ES (errno2EC (err)));
  EXEC_TSTCASE (&tstCase, "Error msg from strerror and ec2ES compare",
		(!retVal), retVal, strerror (err), 0);

  //;
  EXEC_TSTCASE (&tstCase, "Error msg for 0", (ec2ES (0) == NULL), 0,
		ec2ES (0), 0);

  //;
  EXEC_TSTCASE (&tstCase, "Error msg for 1", (ec2ES (1) == NULL), 0,
		ec2ES (1), 0);

  //;
  EXEC_TSTCASE (&tstCase, "Error msg for ERR_BASE_VALUE",
		(ec2ES (-ERR_BASE_VALUE) == NULL), 0, ec2ES (-ERR_BASE_VALUE),
		0);

  //;
  EXEC_TSTCASE (&tstCase, "Error msg for ERR_BASE_VALUE+MAX_ERR_STRING_SIZE",
		(ec2ES (-ERR_BASE_VALUE - MAX_ERR_STRING_SIZE) == NULL), 0,
		ec2ES (-ERR_BASE_VALUE - MAX_ERR_STRING_SIZE), 0);

#if 0
  retVal =
    strcmp (ec2ES (-ERR_BASE_VALUE - MAX_ERR_STRING_SIZE + 1),
	    "Invalid error code value");
  EXEC_TSTCASE (&tstCase,
		"Error msg for ERR_BASE_VALUE+MAX_ERR_STRING_SIZE-1",
		(!retVal), retVal,
		ec2ES (-ERR_BASE_VALUE - MAX_ERR_STRING_SIZE + 1), 0);
#endif

  //;
  EXEC_TSTCASE (&tstCase, "Error msg for SUCCESS", (ec2ES (SUCCESS) == NULL),
		0, ec2ES (SUCCESS), 0);

  retVal = strcmp (ec2ES (FAILURE), "Failed");
  EXEC_TSTCASE (&tstCase, "Error msg for FAILURE", (!retVal), retVal,
		ec2ES (FAILURE), 0);

  hdr ("Testing of emod module compleated");
}
Пример #5
0
void
test_omod (void)
{

  bs_omodCls oObj = NULL;
  bs_opts opts[] =
    { {MANDATORY, "mandatory string", "atest", 'a'}, {OPTIONAL,
						      "optional string",
						      "btest", 'b'},
    {NO_OPTIONS, "no options string", "ctest", 'c'}, {MANDATORY,
						      "mandatory no long string",
						      0, 'd'}, {SUB_COMMAND,
								"sub command -header-",
								"scmd1", 0},
    {MANDATORY, "mandatory string", "etest", 'e'}, {OPTIONAL,
						    "optional string (same as main)",
						    "atest", 'a'},
    {NO_OPTIONS, "no options string", "gtest", 'g'}, {OPTIONAL,
						      "optional no long string",
						      0, 'h'}, {SUB_COMMAND,
								"sub command 2 -header-",
								"scmd2", 0},
    {MANDATORY, "mandatory string", 0, 'i'}, {OPTIONAL, "optional string", 0,
					      'j'}, {NO_OPTIONS,
						     "no options string", 0,
						     'k'}, {OPTIONAL,
							    "optional string",
                        0, 'l'},
      {0} };
  char *args[] =
    { "EXE", "--atest", "a1", "-b", "a2", "--ctest", "-d", "a3", "scmd1",
"--etest", "a4", "-a", "a5", "-g", "-h", "a6", "scmd2", "-i", "a7", "-j", "a8", "-k",
"-l", "a9", "a10" };
  char *userDoc = "User document";
  char *helpDoc = "Help \v document";
  char *userData = "User Data";
  int cnt = 25;

  hdr ("Testing of omod module started");

  retVal = bs_omodInit (&oObj, userDoc, helpDoc, opts, &userParseFun, iMObj);
  EXEC_TSTCASE (&tstCase, " Initialize the options module ", retVal, retVal,
		ec2ES (retVal), 0);

  retVal = bs_parseOpts (oObj, cnt, args, userData);
  EXEC_TSTCASE (&tstCase, " Start parsing the options ", retVal, retVal,
		ec2ES (retVal), 0);

  retVal = bs_omodFin (&oObj, iMObj);
  EXEC_TSTCASE (&tstCase, " Finalise the options module ", retVal, retVal,
		ec2ES (retVal), 0);

  hdr ("Testing of omod module compleated");
}
Пример #6
0
    /** Override \p ff_node's \p push method */
    virtual inline bool push(void * ptr) {
        if (skipdnode || !P) return ff_node::push(ptr);

        // gets the peers involved in one single communication
        const int peers=com.getDescriptor()->getPeers();
        if (ptr == (void*)FF_EOS) {
            //cerr << "DNODE prepare to send FF_DEOS to " << peers <<" peers\n";
            for(int i=0;i<peers;++i) {
                msg_t msg;
                msg.init(FF_DEOS,msg_t::HEADER_LENGHT);
                //cerr << "DNODE sends FF_DEOS to " << i <<"\n";
                if (!com.put(msg,i)) return false;
            }
            return true;
        }

        if (CommImpl::MULTIPUT) {
            svector<iovec> v;
            for(int i=0;i<peers;++i) {
                v.clear();
                callbackArg.resize(0);
                prepare(v, ptr, i);

                msg_t hdr(new uint32_t(v.size()), msg_t::HEADER_LENGHT, freeHdr);
                com.putmore(hdr,i);
                callbackArg.resize(v.size());
                for(size_t j=0;j<v.size()-1;++j) {
                    msg_t msg(v[j].iov_base, v[j].iov_len,freeMsg,callbackArg[j]);
                    com.putmore(msg,i);
                }
                msg_t msg(v[v.size()-1].iov_base, v[v.size()-1].iov_len,freeMsg,callbackArg[v.size()-1]);
                if (!com.put(msg,i)) return false;
            }
        } else {
            svector<iovec> v;
            callbackArg.resize(0);
            prepare(v, ptr);

            msg_t hdr(new uint32_t(v.size()), msg_t::HEADER_LENGHT, freeHdr);
            com.putmore(hdr);
            callbackArg.resize(v.size());
            for(size_t j=0;j<v.size()-1;++j) {
                msg_t msg(v[j].iov_base, v[j].iov_len,freeMsg,callbackArg[j]);
                com.putmore(msg);
            }
            msg_t msg(v[v.size()-1].iov_base, v[v.size()-1].iov_len,freeMsg,callbackArg[v.size()-1]);
            if (!com.put(msg)) return false;
        }
        return true;
    }
// write the assembly model in STEP format
bool PCBMODEL::WriteSTEP( const std::string& aFileName, bool aOverwrite )
{
    if( m_pcb_label.IsNull() )
    {
        std::ostringstream ostr;
        ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
        ostr << "  * No valid PCB assembly; cannot create output file " << aFileName << "\n";
        wxLogMessage( "%s\n", ostr.str().c_str() );
        return false;
    }

    STEPCAFControl_Writer writer;
    writer.SetColorMode( Standard_True );
    writer.SetNameMode( Standard_True );

    if( Standard_False == writer.Transfer( m_doc, STEPControl_AsIs ) )
        return false;

    APIHeaderSection_MakeHeader hdr( writer.ChangeWriter().Model() );
    wxFileName fn( aFileName );
    hdr.SetName( new TCollection_HAsciiString( fn.GetFullName().ToUTF8() ) );
    // TODO: how to control and ensure consistency with IGES?
    hdr.SetAuthorValue( 1, new TCollection_HAsciiString( "An Author" ) );
    hdr.SetOrganizationValue( 1, new TCollection_HAsciiString( "A Company" ) );
    hdr.SetOriginatingSystem( new TCollection_HAsciiString( "KiCad to STEP converter" ) );
    hdr.SetDescriptionValue( 1, new TCollection_HAsciiString( "KiCad electronic assembly" ) );

    if( Standard_False == writer.Write( aFileName.c_str() ) )
        return false;

    return true;
}
Пример #8
0
ResourceData::~ResourceData() {
  auto id = getId();
  if (id && id == *s_max_resource_id) {
    --*s_max_resource_id;
  }
  hdr()->setRawId(-1);
}
Пример #9
0
std::ostream& rspfDtedInfo::print(std::ostream& out) const
{
   if ( theFile.size() )
   {
      std::string prefix = "dted.";
      
      rspfDtedVol vol(theFile, 0);
      rspfDtedHdr hdr(theFile, vol.stopOffset());
      rspfDtedUhl uhl(theFile, hdr.stopOffset());
      rspfDtedDsi dsi(theFile, uhl.stopOffset());
      rspfDtedAcc acc(theFile, dsi.stopOffset());
      if( vol.getErrorStatus() == rspfErrorCodes::RSPF_OK )
      {
         vol.print(out, prefix);
      }
      if( hdr.getErrorStatus() == rspfErrorCodes::RSPF_OK )
      {
         hdr.print(out, prefix);
      }
      if( uhl.getErrorStatus() == rspfErrorCodes::RSPF_OK )
      {
         uhl.print(out, prefix);
      }
      if( dsi.getErrorStatus() == rspfErrorCodes::RSPF_OK )
      {
         dsi.print(out, prefix);
      }
      if( acc.getErrorStatus() == rspfErrorCodes::RSPF_OK )
      {
         acc.print(out, prefix);
      }
   }
   return out;
}
Пример #10
0
bool rspfDtedInfo::open(const rspfFilename& file)
{
   bool result = false;

   // Test for extension, like dt0, dt1...
   rspfString ext = file.ext();
   rspfRegExp regExp("^[d|D][t|T][0-9]");
   
   if ( regExp.find( ext.c_str() ) )
   {
      rspfDtedVol vol(file, 0);
      rspfDtedHdr hdr(file, vol.stopOffset());
      rspfDtedUhl uhl(file, hdr.stopOffset());
      rspfDtedDsi dsi(file, uhl.stopOffset());
      rspfDtedAcc acc(file, dsi.stopOffset());
      
      //---
      // Check for errors.  Must have uhl, dsi and acc records.  vol and hdr
      // are for magnetic tape only; hence, may or may not be there.
      //---
      if ( (uhl.getErrorStatus() == rspfErrorCodes::RSPF_OK) &&
           (dsi.getErrorStatus() == rspfErrorCodes::RSPF_OK) &&
           (acc.getErrorStatus() == rspfErrorCodes::RSPF_OK) )
      {
         theFile = file;
         result = true;
      }
      else
      {
         theFile.clear();
      }
   }

   return result;
}
Пример #11
0
int SQY_Header_Size(const char* src, long *srclength){

  sqy::header hdr(src, src + *srclength);
  *srclength = hdr.size();

  return 0;
}
int gcomm::AsioUdpSocket::send(const Datagram& dg)
{
    Critical<AsioProtonet> crit(net_);
    boost::array<asio::const_buffer, 3> cbs;
    NetHeader hdr(dg.len(), net_.version_);

    if (net_.checksum_ != NetHeader::CS_NONE)
    {
        hdr.set_crc32(crc32(net_.checksum_, dg), net_.checksum_);
    }

    gu::byte_t buf[NetHeader::serial_size_];
    serialize(hdr, buf, sizeof(buf), 0);
    cbs[0] = asio::const_buffer(buf, sizeof(buf));
    cbs[1] = asio::const_buffer(dg.header() + dg.header_offset(),
                          dg.header_len());
    cbs[2] = asio::const_buffer(&dg.payload()[0], dg.payload().size());
    try
    {
        socket_.send_to(cbs, target_ep_);
    }
    catch (asio::system_error& err)
    {
        log_warn << "Error: " << err.what();
        return err.code().value();
    }
    return 0;
}
Пример #13
0
void do_cat(char *f, int fd)
{
  char *ext=f_typ(f+2);  // extension
  char *cnt="text/plain"; 
  FILE *fs,*ff;
  int c;

  //printf(" cat arg %s \n",f);
  //printf(" cat ext %s \n",ext);

  if (strcmp(ext,"html")==0) cnt="text/html"; //form header compatible the file 
  else if (strcmp(ext,"gif")==0) cnt="image/gif";
  else if (strcmp(ext,"jpg")==0) cnt="image/jpeg";
  fs=fdopen(fd,"w");
  ff=fopen(f,"r");
  if(fs!=NULL && ff!=NULL)
  {
//     printf(" cat %s \n",cnt);
     hdr(fs,cnt);      // send HTTP reply
     fprintf(fs,"\r\n"); 
     while( (c=getc(ff))!=EOF ) putc(c,fs); // send file
     fclose(ff);
     fclose(fs);
  }
  exit(0); // exit the child proc
}
Пример #14
0
        Channel TIDELog::writeCHAN(const std::string& name, const std::string& type, const std::string& source,
                const Array& source_spec, const Array& fmt_spec) {
            // argument checking
            check_bounds("name", 256, name.length());
            check_bounds("type", 10, type.length());
            check_bounds("source", 256, source.length());
            check_bounds("source_spec", 256, source_spec.length);
            check_bounds("fmt_spec", UINT_MAX, fmt_spec.length);

            // header
            HEADER hdr(TAG_CHAN, 4 + 1 + name.length() + type.length() + 4 + 
                        source.length() + 4 + source_spec.length + 4 + fmt_spec.length + 4);

            write_checked<HEADER,HDR_SIZE>(hdr);

            // ID
            const uint32_t id = ++num_chans;
            check_io(1, fwrite(&id, sizeof(id), 1, logfile), "id");
            // name
            write_checked(SArray(name.c_str(), name.length()), "name");
            // type
            write_checked(Array(type.c_str(), type.length()), "type");
            // human-readable source description
            write_checked(Array(source.c_str(), source.length()), "source");
            // source string
            write_checked(source_spec, "spec");
            // format spec
            write_checked(fmt_spec, "format");

            fflush(logfile);

            return Channel(id, name, type, source, source_spec, fmt_spec);
        }
Пример #15
0
int SQY_Decode_UI8(const char* src, long srclength, char* dst, int nthreads){
  int value =1;

  sqy::header hdr(src,src+(srclength));
  std::vector<std::size_t> inshape_  = {std::size_t(srclength)};
  std::vector<std::size_t> outshape_(hdr.shape()->begin(),hdr.shape()->end());

  if(!sqy::dypeline<std::uint8_t>::can_be_built_from(hdr.pipeline())){
    std::cerr << "[sqeazy]\t" << hdr.pipeline() << " cannot be build with this version of sqeazy\n";
    return value;
  }

  auto pipe = sqy::dypeline<std::uint8_t>::from_string(hdr.pipeline());
  pipe.set_n_threads(nthreads);

  if(!pipe.size()){
    std::cerr << "[sqeazy]\t received " << pipe.name() << "pipeline of size 0, no decoding possible\n";
    return value;}


  value = pipe.decode(src,
                      reinterpret_cast<std::uint8_t*>(dst),
                      inshape_,
                      outshape_);

  return value;
}
Пример #16
0
 //Extracts the specified row from across all slices and generates a .dat and
 //a .raw file with this information.
 void VolImage::extractRow(int row, std::string output_prefix){
     //Write header file
     ofstream hdr(output_prefix + ".dat");
     hdr << width << " " << slices.size() << " " << 1 << endl;
     hdr.close();
     
     //Extract the specified row from all the slices
     u_char ** extracted = new u_char * [slices.size()];
     int currRow = 0;
     for(int slice = 0; slice < slices.size(); slice++){
         u_char ** rowsArr = slices[slice];
         extracted[currRow] = rowsArr[row];
         currRow++;
     }
     
     //Write extracted rows to output .raw file
     ofstream out(output_prefix + ".raw", ios::binary);
     for(int row = 0; row < slices.size(); row++){
         out.write((char *)extracted[row], (sizeof(u_char) * width));
     }
     out.close();
     
     //Clean up memory allocated in this method
     delete [] extracted;
 }
Пример #17
0
 //Produces a .dat and a .raw file that illustrate the difference between
 //sliceI and sliceJ. Ouputs the diffmap to the file.
 void VolImage::diffmap(int sliceI, int sliceJ, std::string output_prefix){
     //Write header file
     ofstream hdr(output_prefix + ".dat");
     hdr << width << " " << height << " " << 1 << endl;
     hdr.close();
     
     //Compute the diffmap of the two slices
     u_char ** diffmapArr = new u_char * [height];
     for(int row = 0; row < height; row++){
         diffmapArr[row] = new u_char [width];
         for(int col = 0; col < width; col++){
             diffmapArr[row][col] = (u_char)(abs((float)slices[sliceI][row][col] - (float)slices[sliceJ][row][col])/2);
         }
     }
     
     //Write the diffmap data to the output .raw file one row at a time
     ofstream out(output_prefix + ".raw", ios::binary);
     for(int row = 0; row < height; row++){
         out.write((char *)diffmapArr[row], (sizeof(u_char) * width));
     }
     out.close();
     
     //Clean up memory allocated in this method
     for(int row = 0; row < height; row++){
         delete [] diffmapArr[row];
     }
     delete [] diffmapArr;
 }
Пример #18
0
void c_Closure::init(int numArgs, ActRec* ar, TypedValue* sp) {
  auto const cls = getVMClass();
  auto const invokeFunc = getInvokeFunc();

  if (invokeFunc->cls()) {
    setThisOrClass(ar->getThisOrClass());
    if (invokeFunc->isStatic()) {
      if (!hasClass()) {
        setClass(getThisUnchecked()->getVMClass());
      }
    } else if (!hasClass()) {
      getThisUnchecked()->incRefCount();
    }
  } else {
    hdr()->ctx = nullptr;
  }

  /*
   * Copy the use vars to instance variables, and initialize any
   * instance properties that are for static locals to KindOfUninit.
   */
  auto const numDeclProperties = cls->numDeclProperties();
  assertx(numDeclProperties - numArgs == getInvokeFunc()->numStaticLocals());
  auto beforeCurUseVar = sp + numArgs;
  auto curProperty = getUseVars();
  int i = 0;
  assertx(numArgs <= numDeclProperties);
  for (; i < numArgs; i++) {
    // teleport the references in here so we don't incref
    tvCopy(*--beforeCurUseVar, *curProperty++);
  }
  for (; i < numDeclProperties; ++i) {
    tvWriteUninit(*curProperty++);
  }
}
Пример #19
0
static int rpmsg_probe(struct rpmsg_channel *_rpdev)
{
	struct dce_rpc_connect_req req = {
			.hdr = MKHDR(CONNECT),
			.chipset_id = GET_OMAP_TYPE,
			.debug = drm_debug ? 1 : 3,
	};
	int ret;

	DBG("");
	rpdev = _rpdev;

	/* send connect msg: */
	ret = rpsend(NULL, NULL, hdr(&req), sizeof(req));
	if (ret) {
		DBG("rpsend failed: %d", ret);
		return ret;
	}

	return omap_drm_register_plugin(&plugin);
}

static void __devexit rpmsg_remove(struct rpmsg_channel *_rpdev)
{
	DBG("");
	omap_drm_unregister_plugin(&plugin);
	rpdev = NULL;
}
Пример #20
0
////////////////////////////////////////////////////////////////
// FunSig
void FunSig::display( int indent, std::ostream& os )
{
	os << "<FunSig " << name->source->s;
	if( name->fresh ) { os << "~" << name->fresh->s; }
	os << " = ( " << dsp( 0, fargs ) << " ): "
	   << dsp( 0, result_type ) << ">" << hdr( h );
}
Пример #21
0
    BamFilePrivate(const std::string& fn)
        : filename_(fn)
        , firstAlignmentOffset_(-1)
    {
        // ensure we've updated htslib verbosity with requested verbosity here
        hts_verbose = ( PacBio::BAM::HtslibVerbosity == -1 ? 0 : PacBio::BAM::HtslibVerbosity);

        // attempt open
        auto f = RawOpen();

#if !defined (PBBAM_NO_CHECK_EOF) || PBBAM_AUTOVALIDATE
        // sanity check on file
        const int eofCheck = bgzf_check_EOF(f->fp.bgzf);
        if (eofCheck <= 0 ) {
            // 1:  EOF present & correct
            // 2:  not seekable (e.g. reading from stdin)
            // 0:  EOF absent
            // -1: some other error
            std::stringstream e;
            if (eofCheck == 0)
                e << fn << " : is missing EOF block" << std::endl;
            else
                e << fn << " : unknown error while checking EOF block" << std::endl;
            throw std::runtime_error(e.str());
        }
#endif

        // attempt fetch header
        std::unique_ptr<bam_hdr_t, internal::HtslibHeaderDeleter> hdr(sam_hdr_read(f.get()));
        header_ = internal::BamHeaderMemory::FromRawData(hdr.get());

        // cache first alignment offset
        firstAlignmentOffset_ = bgzf_tell(f->fp.bgzf);
    }
Пример #22
0
static void
send_identification_packet()
{
        try {
		AOStreamBE hdr(sOutgoingFrame->data, kStarPacketHeaderSize);
                AOStreamBE ps(sOutgoingFrame->data, ddpMaxData, kStarPacketHeaderSize);
        
		// Message type
		hdr << (uint16) kSpokeToHubIdentification;
        
                // ID
                ps << (uint16)sLocalPlayerIndex;

		// blank out the CRC field before calculating
		sOutgoingFrame->data[2] = 0;
		sOutgoingFrame->data[3] = 0;

		uint16 crc = calculate_data_crc_ccitt(sOutgoingFrame->data, ps.tellp());
		hdr << crc;

                // Send the packet
                sOutgoingFrame->data_size = ps.tellp();
                if(sHubIsLocal)
                        send_frame_to_local_hub(sOutgoingFrame, &sHubAddress, kPROTOCOL_TYPE, 0 /* ignored */);
                else
                        NetDDPSendFrame(sOutgoingFrame, &sHubAddress, kPROTOCOL_TYPE, 0 /* ignored */);
        }
        catch (...) {
        }
}
Пример #23
0
    virtual inline bool push(void * ptr) { 
        if (skipdnode || !P) return ff_node::push(ptr);

        // gets the peers involved in one single communication
        const int peers=com.putToPerform(); 

        if (ptr == (void*)FF_EOS) {
            for(int i=0;i<com.getDescriptor()->getPeers();++i) {
                msg_t msg; 
                msg.init(FF_DEOS,msg_t::HEADER_LENGHT);
                if (!com.put(msg,i)) return false;
            }
            return true;
        }

        svector<iovec> v[peers];
        for(int i=0;i<peers;++i) {
            callbackArg.resize(0);
            prepare(v[i], ptr, i);

            uint32_t *len = new uint32_t(v[i].size());
            msg_t hdr(len, msg_t::HEADER_LENGHT, freeHdr);
            com.putmore(hdr);
            callbackArg.resize(*len);
            for(size_t j=0;j<v[i].size()-1;++j) {
                msg_t msg(v[i][j].iov_base, v[i][j].iov_len,freeMsg,callbackArg[j]); 
                com.putmore(msg);
            }
            msg_t msg(v[i][*len-1].iov_base, v[i][*len-1].iov_len,freeMsg,callbackArg[*len-1]);
            if (!com.put(msg)) return false;
        }
        return true;
    }
Пример #24
0
void forward(universal_t *objref) {
  universal_t *ptr = *((universal_t **)objref);
  if (is_ptr(ptr) && (ptr >= curbot && ptr < curtop)) {
    /* ptr is a pointer into an object in fromspace */
    if (is_rec(ptr)) {
      /* Get a pointer to the header */
      universal_t *header = hdr(ptr);
      /* Retrieve the length of the record (plus one for the header) */
      universal_t len = rec_len(ptr) + 1;
      /* Copy the object starting at the header into tosapce */
      universal_t *i = header;;
      universal_t *j = endptr;
      while (len-- > 0) {
	*j++ = *i++;
      }
      /* Set the forwarding pointer in fromspace and update the record's tag */
      *ptr = (universal_t)(endptr + 1);
      *header = UINTPTR_MAX;
      /* Move the end of the queue forward */
      endptr = j;
    }
    /* ptr must be a forwarding pointer. It either already was, or we 
       forwarded it above. Update the objref to point to the new object */
    *objref = *(universal_t *)ptr;
  }
}
Пример #25
0
  actor_id spawn(actor sire, F&& f, fiber_meta meta)
  {
    // Create actor handler.
    actor_handler_t hdr(f);

    // Generate actor_id.
    auto aid = generate_actor_id();

    // Spawn an coctx.
    asev::strand_t snd(*evs_);
    auto sire_aid = sire == nullactor ? nullaid : sire.get_actor_id();
    if (sire_aid != nullaid && meta.ssire_)
    {
      snd = sire.get_strand();
    }

    snd.spawn(
      [this, sire_aid, hdr, aid](asev::corctx_t& ctx)
      {
        // Alloc fiber_actor.
        auto a = fiber_actor_pool_->get();
        // Run actor.
        a->init(aid, ctx.get_strand());
        a->run(ctx, sire_aid, std::move(hdr));
      },
      coctx::make_stacksize(meta.ssize_)
      );
    return aid;
  }
Пример #26
0
//////////////////////////////////////////////////////////////////////////////
/// @param[in] p_rgMsg	Message to send.
/// @param[in] p_nMsgSz	Size of the message to be sent.
/// @retval none
//////////////////////////////////////////////////////////////////////////////
void CHartUpLink::WirelessRequest( uint8_t p_rgMsg[], size_t p_nMsgSz, unsigned int p_nHandle=0 )
{
    if ( m_nLinkState == EUDP_LINK_DISCONNECTED )
        return SessionInit() ;

    HartPDUHdr hdr( CHartUpMatcher::EPKT_WREQUEST );
    hdr.SetByteCount( networkorder16(sizeof(HartPDUHdr) + p_nMsgSz) );

    ProtocolPacketPtr pkt = ProtocolPacketPtr(new ProtocolPacket) ;
    pkt->AllocateCopy( (uint8_t*)&hdr, sizeof(hdr), 0, p_nMsgSz ) ;
    pkt->PushBack(p_rgMsg, p_nMsgSz);

    if ( p_nHandle )
    {
        HartPDUHdr::access(pkt)->m_ui16TransactId = p_nHandle ;
        p_nHandle = hostorder16(p_nHandle);
        //LOG( "%s UpLink.WirelessRequest [BigEndian] (Handle:x%04X)", m_szName, p_nHandle );
    }
    else
    {
        HartPDUHdr::access(pkt)->m_ui16TransactId = networkorder16(m_nHandle--) ;
        //LOG( "%s UpLink.WirelessRequest [LittleEndian] (Handle:x%04X)", m_szName, HartPDUHdr::access(pkt)->m_ui16TransactId );
    }
    unsigned handle = m_pMsgQ->Enque( EQ_UDP_NORMAL, pkt, p_nHandle );
    if (handle)
    {
        HartPDUHdr::access(pkt)->m_ui16TransactId = networkorder16(handle );
        m_pMsgQ->StartXmit() ;
    }
    else
    {
//	    delete pkt;
    }

}
Пример #27
0
	//--------------------------------------------------------------------------
	std::ofstream& DualOFStream::src()
	{
		if( _src )
			return *_src;

		return hdr();
	}
Пример #28
0
Mat UMat::getMat(int accessFlags) const
{
    if(!u)
        return Mat();
    // TODO Support ACCESS_READ (ACCESS_WRITE) without unnecessary data transfers
    accessFlags |= ACCESS_RW;
    UMatDataAutoLock autolock(u);
    if(CV_XADD(&u->refcount, 1) == 0)
        u->currAllocator->map(u, accessFlags);
    if (u->data != 0)
    {
        Mat hdr(dims, size.p, type(), u->data + offset, step.p);
        hdr.flags = flags;
        hdr.u = u;
        hdr.datastart = u->data;
        hdr.data = u->data + offset;
        hdr.datalimit = hdr.dataend = u->data + u->size;
        return hdr;
    }
    else
    {
        CV_XADD(&u->refcount, -1);
        CV_Assert(u->data != 0 && "Error mapping of UMat to host memory.");
        return Mat();
    }
}
Пример #29
0
void createEncryptedEpubWarningDocument(ldomDocument * m_doc) {
    CRLog::error("EPUB document contains encrypted items");
    ldomDocumentWriter writer(m_doc);
    writer.OnTagOpenNoAttr(NULL, L"body");
    writer.OnTagOpenNoAttr(NULL, L"h3");
    lString16 hdr(L"Encrypted content");
    writer.OnText(hdr.c_str(), hdr.length(), 0);
    writer.OnTagClose(NULL, L"h3");

    writer.OnTagOpenAndClose(NULL, L"hr");

    writer.OnTagOpenNoAttr(NULL, L"p");
    lString16 txt(L"This document is encrypted (has DRM protection).");
    writer.OnText(txt.c_str(), txt.length(), 0);
    writer.OnTagClose(NULL, L"p");

    writer.OnTagOpenNoAttr(NULL, L"p");
    lString16 txt2(L"Cool Reader doesn't support reading of DRM protected books.");
    writer.OnText(txt2.c_str(), txt2.length(), 0);
    writer.OnTagClose(NULL, L"p");

    writer.OnTagOpenNoAttr(NULL, L"p");
    lString16 txt3(L"To read this book, please use software recommended by book seller.");
    writer.OnText(txt3.c_str(), txt3.length(), 0);
    writer.OnTagClose(NULL, L"p");

    writer.OnTagOpenAndClose(NULL, L"hr");

    writer.OnTagOpenNoAttr(NULL, L"p");
    lString16 txt4(L"");
    writer.OnText(txt4.c_str(), txt4.length(), 0);
    writer.OnTagClose(NULL, L"p");

    writer.OnTagClose(NULL, L"body");
}
Пример #30
0
/* Write bytes to the DataStore, to a location that is already
   allocated
 */
void
DataStore::writeData(off_t off,
                     void const* buffer,
                     size_t len,
                     size_t allocatedSize)
{
    ScopedMutexLock sm(_dslock);

    DiskChunkHeader hdr(false, allocatedSize);
    struct iovec iovs[2];

    /* Set up the iovecs
     */
    iovs[0].iov_base = (char*) &hdr;
    iovs[0].iov_len = sizeof(DiskChunkHeader);
    iovs[1].iov_base = (char*) buffer;
    iovs[1].iov_len = len;

    /* Issue the write
     */
    _file->writeAllv(iovs, 2, off);

    /* Update the dirty flag and schedule flush if necessary
     */
    if (!_dirty)
    {
        _dirty = true;
        _dsm->getFlusher().add(_guid);
    }
}