Example #1
0
uint32_t tgen_generate_debug_chunk(const char * filename,
                                   uint32_t x, uint32_t y)
{
    // restore heap
    mem.restore_heap(saved_heap);

    cpu.reset_stack();
    cpu.push_dword(y);
    cpu.push_dword(x);
    get_self() = MANAGER_ADDRESS;
    add_ret();
    generator_func();

    // save_chunk_now();
    // return 0;
    // address 405E30 is
    // void * __thiscall get_sector_chunk_data(__int64 chunk_pos)
    cpu.push_dword(y);
    cpu.push_dword(x);
    get_self() = MANAGER_ADDRESS;
    add_ret();
    sub_405E30();
    uint32_t chunk_offset = cpu.reg[EAX];
    tgen_dump_mem(filename);

    return chunk_offset;
}
Example #2
0
/* 
 * Start the backup of a specific file
 */
static bRC startBackupFile(bpContext *ctx, struct save_pkt *sp)
{
   delta_test *self = get_self(ctx);
   if (!self) {
      return bRC_Error;
   }
   time_t now = time(NULL);
   sp->fname = (char *)"/delta.txt";
   sp->type = FT_REG;
   sp->statp.st_mode = 0700 | S_IFREG;
   sp->statp.st_ctime = now;
   sp->statp.st_mtime = now;
   sp->statp.st_atime = now;
   sp->statp.st_size = -1;
   sp->statp.st_blksize = 4096;
   sp->statp.st_blocks = 1;
   if (self->level == 'I' || self->level == 'D') {
      bRC state = bfuncs->checkChanges(ctx, sp);
      /* Should always be bRC_OK */
      sp->type = (state == bRC_Seen)? FT_NOCHG : FT_REG;
      sp->flags |= (FO_DELTA|FO_OFFSETS);
      self->delta = sp->delta_seq + 1;
   }
   pm_strcpy(self->fname, files[self->delta % nb_files]);
   Dmsg(ctx, dbglvl, "delta-test-fd: delta_seq=%i delta=%i fname=%s\n", 
        sp->delta_seq, self->delta, self->fname);
// Dmsg(ctx, dbglvl, "delta-test-fd: startBackupFile\n");
   return bRC_OK;
}
Example #3
0
/*
 * This is called during restore to create the file (if necessary)
 * We must return in rp->create_status:
 *   
 *  CF_ERROR    -- error
 *  CF_SKIP     -- skip processing this file
 *  CF_EXTRACT  -- extract the file (i.e.call i/o routines)
 *  CF_CREATED  -- created, but no content to extract (typically directories)
 *
 */
static bRC createFile(bpContext *ctx, struct restore_pkt *rp)
{
   delta_test *self = get_self(ctx);
   pm_strcpy(self->fname, rp->ofname);
   rp->create_status = CF_EXTRACT;
   return bRC_OK;
}
Example #4
0
SCM ffmpeg_crop_audio_frame_size(SCM scm_self, SCM scm_size)
{
  struct ffmpeg_t *self = get_self(scm_self);
  self->audio_target_frame->nb_samples = scm_to_int(scm_size);
  self->audio_packed_frame->nb_samples = scm_to_int(scm_size);
  return SCM_UNSPECIFIED;
}
Example #5
0
SCM ffmpeg_decode_audio_video(SCM scm_self)
{
  SCM retval = SCM_BOOL_F;

  struct ffmpeg_t *self = get_self(scm_self);

  if (!is_input_context(self))
    scm_misc_error("ffmpeg-decode-audio/video", "Attempt to read frame from FFmpeg output video", SCM_EOL);

  while (scm_is_false(retval)) {
    if (packet_empty(self)) read_packet(self);

    int reading_cache = packet_empty(self);

    if (self->pkt.stream_index == self->audio_stream_idx) {
      av_frame_unref(self->audio_target_frame);
      retval = decode_audio(self, &self->pkt, self->audio_target_frame);
    } else if (self->pkt.stream_index == self->video_stream_idx) {
      av_frame_unref(self->video_target_frame);
      retval = decode_video(self, &self->pkt, self->video_target_frame);
    } else
      consume_packet_data(&self->pkt, self->pkt.size);

    if (scm_is_false(retval) && reading_cache) break;
  };

  return retval;
}
Example #6
0
SCM ffmpeg_target_audio_frame(SCM scm_self)
{
  struct ffmpeg_t *self = get_self(scm_self);
  if (!is_input_context(self))
    make_frame_writable(self->audio_target_frame);
  return list_audio_frame_info(self, self->audio_target_frame);
}
Example #7
0
 /**
  * The ckernel destructor function, which is placed in
  * base.destructor.
  */
 static void destruct(ckernel_prefix *rawself)
 {
   self_type *self = get_self(rawself);
   // If there are any child kernels, a child class
   // must implement this to destroy them.
   self->destruct_children();
   self->~self_type();
 }
Example #8
0
SCM ffmpeg_flush(SCM scm_self)
{
  struct ffmpeg_t *self = get_self(scm_self);
  if (self->video_codec_ctx) avcodec_flush_buffers(self->video_codec_ctx);
  if (self->audio_codec_ctx) avcodec_flush_buffers(self->audio_codec_ctx);
  if (self->audio_buffer.buffer) ringbuffer_flush(&self->audio_buffer);
  return scm_self;
}
Example #9
0
    thread_state_enum at_timer(SchedulingPolicy& scheduler,
        boost::chrono::steady_clock::time_point& abs_time,
        thread_id_type const& thrd, thread_state_enum newstate,
        thread_state_ex_enum newstate_ex, thread_priority priority)
    {
        if (HPX_UNLIKELY(!thrd)) {
            HPX_THROW_EXCEPTION(null_thread_id,
                "threads::detail::at_timer",
                "NULL thread id encountered");
            return terminated;
        }

        // create a new thread in suspended state, which will execute the
        // requested set_state when timer fires and will re-awaken this thread,
        // allowing the deadline_timer to go out of scope gracefully
        thread_id_type self_id = get_self_id();

        boost::shared_ptr<boost::atomic<bool> > triggered(
            boost::make_shared<boost::atomic<bool> >(false));

        thread_init_data data(
            boost::bind(&wake_timer_thread,
                thrd, newstate, newstate_ex, priority,
                self_id, triggered),
            "wake_timer", 0, priority);

        thread_id_type wake_id = invalid_thread_id;
        create_thread(&scheduler, data, wake_id, suspended);

        // create timer firing in correspondence with given time
        typedef boost::asio::basic_deadline_timer<
            boost::chrono::steady_clock
          , util::chrono_traits<boost::chrono::steady_clock>
        > deadline_timer;

        deadline_timer t (
            get_thread_pool("timer-pool")->get_io_service(), abs_time);

        // let the timer invoke the set_state on the new (suspended) thread
        t.async_wait(boost::bind(&detail::set_thread_state,
            wake_id, pending, wait_timeout, priority,
            std::size_t(-1), boost::ref(throws)));

        // this waits for the thread to be reactivated when the timer fired
        // if it returns signaled the timer has been canceled, otherwise
        // the timer fired and the wake_timer_thread above has been executed
        bool oldvalue = false;
        thread_state_ex_enum statex = get_self().yield(suspended);

        if (wait_timeout != statex &&
            triggered->compare_exchange_strong(oldvalue, true)) //-V601
        {
            // wake_timer_thread has not been executed yet, cancel timer
            t.cancel();
        }

        return terminated;
    }
Example #10
0
/*
 * Free a plugin instance, i.e. release our private storage
 */
static bRC freePlugin(bpContext *ctx)
{
   delta_test *self = get_self(ctx);
   if (!self) {
      return bRC_Error;
   }
   delete self;
   return bRC_OK;
}
Example #11
0
SCM ffmpeg_seek(SCM scm_self, SCM scm_position)
{
  struct ffmpeg_t *self = get_self(scm_self);
  if (!is_input_context(self))
    scm_misc_error("ffmpeg-seek", "Attempt to seek in FFmpeg output video", SCM_EOL);

  int64_t position = (int64_t)(scm_to_double(scm_position) * AV_TIME_BASE);
  av_seek_frame(self->fmt_ctx, -1, position, AVSEEK_FLAG_ANY);// TODO: check error
  return scm_position;
}
Example #12
0
static void block(void)
{
	struct mythread_thread* self = get_self();
	pthread_mutex_lock(&g_mutex);
	self->should_run = false;
	pthread_cond_signal(&g_schedule);
	while (!self->should_run) {
		pthread_cond_wait(&self->cv, &g_mutex);
	}
	pthread_mutex_unlock(&g_mutex);
}
Example #13
0
SCM ffmpeg_encode_audio(SCM scm_self)
{
  struct ffmpeg_t *self = get_self(scm_self);
  AVCodecContext *codec = audio_codec_ctx(self);
  AVFrame *audio_frame = self->audio_target_frame;
  audio_frame->pts = av_rescale_q(self->samples_count, (AVRational){1, codec->sample_rate}, codec->time_base);
  self->samples_count += audio_frame->nb_samples;

  encode_audio(self, self->audio_target_frame);
  return SCM_UNSPECIFIED;
}
Example #14
0
Object *new_exception_frame(Object *cxt, Object *frame, Object *ex) {
  Object *catch_frame = new_object(cxt, find_catch_frame(cxt, frame));
  Object *ret_frame = get(cxt, catch_frame, "return");
  Object *self = get_self(cxt, catch_frame);
  Object *catch_block = get_catch_block(cxt, catch_frame);
  Object *new_catch_frame = new_frame(cxt, self, catch_block, ret_frame);
  Object *old_local = get(cxt, catch_frame, "local");
  set_lexical_parent(cxt, new_catch_frame, old_local);
  push(cxt, get(cxt, ret_frame, "stack"), ex);
  return new_catch_frame;
}
Example #15
0
static AVStream *open_output_stream(SCM scm_self, AVCodec *encoder, int *stream_idx, const char *output_type, SCM scm_file_name)
{
  struct ffmpeg_t *self = get_self(scm_self);
  AVStream *retval = avformat_new_stream(self->fmt_ctx, encoder);
  if (!retval) {
    ffmpeg_destroy(scm_self);
    scm_misc_error("make-ffmpeg-output", "Error allocating ~a stream for file '~a'",
                   scm_list_2(scm_from_locale_string(output_type), scm_file_name));
  };
  retval->id = self->fmt_ctx->nb_streams - 1;
  *stream_idx = retval->id;
  return retval;
}
Example #16
0
cyg_bool_t cyg_mutex_lock(cyg_mutex_t* mutex)
{
	struct mythread_mutex* shadow = get_shadow_mutex(mutex);
	struct mythread_thread* self = get_self();

	block();
	while (shadow->locked) {
		block();
	}
	shadow->owner = self->id;
	shadow->locked = true;

	return true;
}
Example #17
0
SCM ffmpeg_encode_video(SCM scm_self)
{
  // TODO: AVFMT_RAWPICTURE
  struct ffmpeg_t *self = get_self(scm_self);
  if (is_input_context(self))
    scm_misc_error("ffmpeg-encode-video", "Attempt to write to FFmpeg input video", SCM_EOL);

  // Set frame timestamp
  self->video_target_frame->pts = self->output_video_pts++;

  encode_video(self, self->video_target_frame);

  return SCM_UNSPECIFIED;
}
Example #18
0
uint32_t tgen_generate_chunk(uint32_t x, uint32_t y)
{
    // restore heap
    mem.restore_heap(saved_heap);

    cpu.reset_stack();
    cpu.push_dword(y);
    cpu.push_dword(x);
    get_self() = MANAGER_ADDRESS;
    add_ret();
    generator_func();

    // save_chunk_now();
    // return 0;
    // address 405E30 is
    // void * __thiscall get_sector_chunk_data(__int64 chunk_pos)
    cpu.push_dword(y);
    cpu.push_dword(x);
    get_self() = MANAGER_ADDRESS;
    add_ret();
    sub_405E30();

    return cpu.reg[EAX];
}
Example #19
0
void basic_local_buffer<Document, Selector>::session_close_impl()
{
	// Remove all users except for the local one
	user_table& table = this->m_user_table;

	for(user_table::iterator iter =
		table.begin(user::flags::CONNECTED, user::flags::NONE);
	    iter != table.end(user::flags::CONNECTED, user::flags::NONE);
	    ++ iter)
	{
		if(&(*iter) == &get_self() ) continue;

		// This tells documents that the user has gone. This causes
		// the user to be unsubscribed from documents
		basic_buffer<Document, Selector>::user_part(*iter);
	}
}
Example #20
0
    /**
     * Initializes an instance of this ckernel in-place according to the
     * kernel request. This calls the constructor in-place, and initializes
     * the base function and destructor
     */
    static inline self_type *init(ckernel_prefix *rawself,
                                  kernel_request_t kernreq)
    {
      // Alignment requirement of the type
      DYND_STATIC_ASSERT((size_t)scalar_align_of<self_type>::value <=
                             (size_t)scalar_align_of<uint64_t>::value,
                         "ckernel types require alignment <= 64 bits");

      // Call the constructor in-place
      self_type *self = new (rawself) self_type();
      // Double check that the C++ struct layout is as we expect
      if (self != get_self(rawself)) {
        throw std::runtime_error(
            "internal ckernel error: struct layout is not valid");
      }
      self->base.destructor = &self_type::destruct;
      // A child class must implement this to fill in self->base.function
      self->init_kernfunc(kernreq);
      return self;
    }
Example #21
0
static int l_obj_is_optional(lua_State* L)
{
    struct obj* self = get_self(L);
    lua_pushboolean(L, self->is_optional);
    return 1;
}
Example #22
0
static int l_obj_children(lua_State* L)
{
    struct obj* self = get_self(L);
    struct obj* children = self->children;
    return children ? get_new_obj(L, children) : 0;
}
Example #23
0
static int l_obj_length(lua_State* L)
{
    struct obj* self = get_self(L);
    lua_pushinteger(L, self->length);
    return 1;
}
Example #24
0
static int l_obj_name(lua_State* L)
{
    struct obj* self = get_self(L);
    lua_pushstring(L, self->name);
    return 1;
}
Example #25
0
static int l_obj_ctype(lua_State* L)
{
    struct obj* self = get_self(L);
    lua_pushstring(L, obj_strctype(self));
    return 1;
}
Example #26
0
static int l_obj_next(lua_State* L)
{
    struct obj* self = get_self(L);
    struct obj* next = self->next;
    return next ? get_new_obj(L, next) : 0;
}
Example #27
0
/*
 * Bacula is calling us to do the actual I/O
 */
static bRC pluginIO(bpContext *ctx, struct io_pkt *io)
{
   delta_test *self = get_self(ctx);
   struct stat statp;
   if (!self) {
      return bRC_Error;
   }
    
   io->status = 0;
   io->io_errno = 0;
   switch(io->func) {
   case IO_OPEN:
      Dmsg(ctx, dbglvl, "delta-test-fd: IO_OPEN\n");
      if (io->flags & (O_CREAT | O_WRONLY)) {
         /* TODO: if the file already exists, the result is undefined */
         if (stat(io->fname, &statp) == 0) { /* file exists */
            self->fd = fopen(io->fname, "r+");
         } else {
            self->fd = fopen(io->fname, "w"); /* file doesn't exist,create it */
         }
         if (!self->fd) {
            io->io_errno = errno;
            Jmsg(ctx, M_FATAL, 
                 "Open failed: ERR=%s\n", strerror(errno));
            return bRC_Error;
         }

      } else {
         self->fd = fopen(self->fname, "r");
         if (!self->fd) {
            io->io_errno = errno;
            Jmsg(ctx, M_FATAL, 
               "Open failed: ERR=%s\n", strerror(errno));
            return bRC_Error;
         }
      }
      break;

   case IO_READ:
      if (!self->fd) {
         Jmsg(ctx, M_FATAL, "Logic error: NULL read FD\n");
         return bRC_Error;
      }
      if (self->done) {
         io->status = 0;
      } else {
         /* first time, read 300, then replace 50-250 by other data */
         if (self->delta == 0) {
            io->status = fread(io->buf, 1, 400, self->fd);            
         } else {
            io->offset = self->delta * 100 / 2; /* chunks are melted */
            io->status = fread(io->buf, 1, 100, self->fd);
         }
         Dmsg(ctx, dbglvl, "delta-test-fd: READ offset=%lld\n", (int64_t)io->offset);
         self->done = true;
      }
      if (io->status == 0 && ferror(self->fd)) {
         Jmsg(ctx, M_FATAL, 
            "Pipe read error: ERR=%s\n", strerror(errno));
         Dmsg(ctx, dbglvl, 
            "Pipe read error: ERR=%s\n", strerror(errno));
         return bRC_Error;
      }
      Dmsg(ctx, dbglvl, "offset=%d\n", io->offset);
      break;

   case IO_WRITE:
      if (!self->fd) {
         Jmsg(ctx, M_FATAL, "Logic error: NULL write FD\n");
         return bRC_Error;
      }
      Dmsg(ctx, dbglvl, "delta-test-fd: WRITE count=%lld\n", (int64_t)io->count);
      io->status = fwrite(io->buf, 1, io->count, self->fd);
      if (io->status == 0 && ferror(self->fd)) {
         Jmsg(ctx, M_FATAL, 
            "Pipe write error\n");
         Dmsg(ctx, dbglvl, 
            "Pipe read error: ERR=%s\n", strerror(errno));
         return bRC_Error;
      }
      break;

   case IO_CLOSE:
      if (!self->fd) {
         Jmsg(ctx, M_FATAL, "Logic error: NULL FD on delta close\n");
         return bRC_Error;
      }
      io->status = fclose(self->fd);
      break;

   case IO_SEEK:
      if (!self->fd) {
         Jmsg(ctx, M_FATAL, "Logic error: NULL FD on delta close\n");
         return bRC_Error;
      }
      Dmsg(ctx, dbglvl, "delta-test-fd: SEEK offset=%lld\n", (int64_t)io->offset);
      io->status = fseek(self->fd, io->offset, io->whence);
      Dmsg(ctx, dbglvl, "after SEEK=%lld\n", (int64_t)ftell(self->fd));
      break;
   }
   return bRC_OK;
}
Example #28
0
const std::string& basic_local_buffer<Document, Selector>::get_name() const
{
	return get_self().get_name();
}
Example #29
0
/*
 * Handle an event that was generated in Bacula
 */
static bRC handlePluginEvent(bpContext *ctx, bEvent *event, void *value)
{
   delta_test *self = get_self(ctx);
   int accurate=0;

   if (!self) {
      return bRC_Error;
   }

// char *name;

   /*
    * Most events don't interest us so we ignore them.
    *   the printfs are so that plugin writers can enable them to see
    *   what is really going on.
    */
   switch (event->eventType) {
   case bEventPluginCommand:
//    Dmsg(ctx, dbglvl, 
//         "delta-test-fd: PluginCommand=%s\n", (char *)value);
      break;
   case bEventJobStart:
//    Dmsg(ctx, dbglvl, "delta-test-fd: JobStart=%s\n", (char *)value);
      break;
   case bEventJobEnd:
//    Dmsg(ctx, dbglvl, "delta-test-fd: JobEnd\n");
      break;
   case bEventStartBackupJob:
//    Dmsg(ctx, dbglvl, "delta-test-fd: StartBackupJob\n");
      break;
   case bEventEndBackupJob:
//    Dmsg(ctx, dbglvl, "delta-test-fd: EndBackupJob\n");
      break;
   case bEventLevel:
//    Dmsg(ctx, dbglvl, "delta-test-fd: JobLevel=%c %d\n", (int)value, (int)value);
      self->level = (int)(intptr_t)value;
      break;
   case bEventSince:
//    Dmsg(ctx, dbglvl, "delta-test-fd: since=%d\n", (int)value);
      break;

   case bEventStartRestoreJob:
//    Dmsg(ctx, dbglvl, "delta-test-fd: StartRestoreJob\n");
      break;

   case bEventEndRestoreJob:
//    Dmsg(ctx, dbglvl, "delta-test-fd: EndRestoreJob\n");
      break;

   /* Plugin command e.g. plugin = <plugin-name>:<name-space>:read command:write command */
   case bEventRestoreCommand:
//    Dmsg(ctx, dbglvl, "delta-test-fd: EventRestoreCommand cmd=%s\n", (char *)value);
      /* Fall-through wanted */
      break;
   case bEventBackupCommand:
      Dmsg(ctx, dbglvl, "delta-test-fd: pluginEvent cmd=%s\n", (char *)value);
      if (self->level == 'I' || self->level == 'D') {
         bfuncs->getBaculaValue(ctx, bVarAccurate, (void *)&accurate);
         if (!accurate) {       /* can be changed to FATAL */
            Jmsg(ctx, M_FATAL, 
                 "Accurate mode should be turned on when using the "
                 "delta-test plugin\n");
            return bRC_Error;
         }
      }
      break;

   default:
//    Dmsg(ctx, dbglvl, "delta-test-fd: unknown event=%d\n", event->eventType);
      break;
   }
   return bRC_OK;
}
Example #30
0
 thread_self::impl_type* get_ctx_ptr()
 {
     return hpx::util::coroutines::detail::coroutine_accessor::get_impl(get_self());
 }