Example #1
0
/* Remove the heap chunk [chunk] from the heap and give the memory back
   to [free].
*/
void caml_shrink_heap (char *chunk)
{
  char **cp;
  asize_t i;

  /* Never deallocate the first block, because caml_heap_start is both the
     first block and the base address for page numbers, and we don't
     want to shift the page table, it's too messy (see above).
     It will never happen anyway, because of the way compaction works.
     (see compact.c)
  */
  if (chunk == caml_heap_start) return;

  caml_stat_heap_size -= Chunk_size (chunk);
  caml_gc_message (0x04, "Shrinking heap to %luk bytes\n",
                   caml_stat_heap_size / 1024);

#ifdef DEBUG
  {
    mlsize_t i;
    for (i = 0; i < Wsize_bsize (Chunk_size (chunk)); i++){
      ((value *) chunk) [i] = Debug_free_shrink;
    }
  }
#endif

  -- caml_stat_heap_chunks;

  /* Remove [chunk] from the list of chunks. */
  cp = &caml_heap_start;
  while (*cp != chunk) cp = &(Chunk_next (*cp));
  *cp = Chunk_next (chunk);

  /* Remove the pages of [chunk] from the page table. */
  for (i = Page (chunk); i < Page (chunk + Chunk_size (chunk)); i++){
    caml_page_table [i] = Not_in_heap;
  }

  /* Free the [malloc] block that contains [chunk]. */
  caml_free_for_heap (chunk);
}
Example #2
0
InfoPane::InfoPane(wxWindow* parent) : cbAuiNotebook(parent, idNB, wxDefaultPosition, wxDefaultSize, infopane_flags), baseID(wxNewId())
{
    defaultBitmap = cbLoadBitmap(ConfigManager::GetDataFolder() + _T("/images/edit_16x16.png"), wxBITMAP_TYPE_PNG);
    if (Manager::Get()->GetConfigManager(_T("app"))->ReadBool(_T("/environment/infopane_tabs_bottom"), false))
        SetWindowStyleFlag(GetWindowStyleFlag() | wxAUI_NB_BOTTOM);

    wxRegisterId(baseID + num_pages);
    for(int i = 0; i < num_pages; ++i)
    {
        page[i] = Page();
    }
}
Example #3
0
 void set(int key, int value) {
     if(index_map.find(key)!=index_map.end()){               //如果该页面存在
         index_map[key]->value=value;                        //将该页面的内容重新设置
         pages.splice(pages.begin(),pages,index_map[key]);   //将该页面置为最近被访问的,即将其调整到表头;
     }else{                                                  //如果该页面不存在,则需要创建新页面
         if(pages.size()==capacity){                         //如果此时已经达到容量上限,则将最后被访问的页面删除,
              index_map.erase(pages.back().key);             //删除第一步:将最后被访问的页面从页面索引中删除
              pages.pop_back();                              //删除第二步:将该页面从页面列表中删除
         }
         pages.push_front(Page(key,value));                  //新建页面,并将其置为最近被访问的,即将其插入到表头;
         index_map[key]=pages.begin();                       //为该页面创建索引
     }
 }
Example #4
0
void BufferManager::start() {
	// Clear variables
	for (int i = 0; i < 2; i++) {
		pages[i] = Page();
		pageNums[i] = 0;
		dirtied[i] = 0;
		pinned[i] = 0;
	}

	// Load pages from disk
	pageIn(0, 1);
	pageIn(1, 2);
}
Example #5
0
SpeedDial::Page SpeedDial::pageForUrl(const QUrl &url)
{
    ENSURE_LOADED;

    const QString urlString = url.toString();

    foreach (const Page &page, m_webPages) {
        if (page.url == urlString) {
            return page;
        }
    }

    return Page();
}
Example #6
0
void BufferManager::pageIn(int index, int pageNum) {
	// Read page data from disk into buffer
	char buffer[4096] = {};
	int blockOffset = getBlockOffset(pageNum);
	fm->read(dbName, blockOffset, 8, buffer);

	// Create page
	pages[index] = Page(buffer);

	// Set page status
	pageNums[index] = pageNum;
	dirtied[index] = 0;
	pinned[index] = 0;
}
Example #7
0
int main(int argc, char* argv[]) {
	app = Gtk::Application::create(argc, argv, "com.squgeim.typer");

	try {
		builder = Gtk::Builder::create_from_file("glade.xml");
	}
	catch(const Glib::FileError& ex) {
		std::cerr<<"FileError: "<<ex.what()<<std::endl;
		return -1;
	}
	catch(const Glib::MarkupError& ex) {
		std::cerr<<"MarkupError: "<<ex.what()<<std::endl;
		return -1;
	}
	catch(const Gtk::BuilderError& ex) {
		std::cerr<<"BuilderError: "<<ex.what()<<std::endl;
		return -1;
	}

	try {
		myWidget <Gtk::Window> mainwin("main");
		MenuButton menu[4];
		for(int i=0;i<4;i++) menu[i]=MenuButton(MenuButton::menubtns[i]);
		for(int i=0;i<4;i++) pages[i]=Page(Page::pgs[i]);
		pages[4]=Page("welcome");
		
		myWidget <Gtk::Button> filestart("filestart");
		filestart->signal_clicked().connect(sigc::ptr_fun(startfile));
		
		app->run(*mainwin.rtr());
		//app->run(*(mainwin->));
	}
	catch(int) {
		std::cerr<<"The main window was not found in the xml."<<std::endl;
		return -1;
	}
}
Example #8
0
int caml_page_table_lookup(void * addr)
{
  uintnat h, e;

  h = Hash(Page(addr));
  /* The first hit is almost always successful, so optimize for this case */
  e = caml_page_table.entries[h];
  if (Page_entry_matches(e, (uintnat)addr)) return e & 0xFF;
  while(1) {
    if (e == 0) return 0;
    h = (h + 1) & caml_page_table.mask;
    e = caml_page_table.entries[h];
    if (Page_entry_matches(e, (uintnat)addr)) return e & 0xFF;
  }
}
Example #9
0
void DocReport::Put(const Paragraph& p) {
	if(dortf) rtf.Put(p);
	SkipBefore(p.GetBefore());
	if(valrects) {
		int y = ypos;
		Vector<ValueRect> v;
		p.GetValueRects(1024, *this, lm, y, pgsz.cx - lm, v);
		AddVR(v);
	}
	Paragraph::PaintInfo pi;
	while(p.Paint(*this, lm, ypos, pgsz.cx - lm, GetYLim(), pi))
		Page();
	SetYPos(pi.ypos);
	SkipAfter(p.GetAfter());
}
Example #10
0
void DocReport::Put(const Table& tab) {
	if(dortf) rtf.Put(tab);
	SkipBefore(tab.GetBefore());
	if(valrects) {
		int y = ypos;
		Vector<ValueRect> v;
		tab.GetValueRects(1024, *this, lm, y, pgsz.cx - lm, v);
		AddVR(v);
	}
	Table::PaintInfo pi;
	while(tab.Paint(*this, lm, ypos, pgsz.cx - lm, GetYLim(), pi))
		Page();
	SetYPos(pi.ypos);
	SkipAfter(tab.GetAfter());
}
Example #11
0
SpeedDial::Page SpeedDial::pageForUrl(const QUrl &url)
{
    ENSURE_LOADED;

    QString urlString = url.toString();
    if (urlString.endsWith(QL1C('/')))
        urlString = urlString.left(urlString.size() - 1);

    foreach (const Page &page, m_pages) {
        if (page.url == urlString) {
            return page;
        }
    }

    return Page();
}
Example #12
0
void Report::Put(const RichText& txt, void *context)
{
	PageY py(pagei, y);
	LLOG("Put RichText, py: " << py << ", pagerect: " << GetPageRect());
	PaintInfo paintinfo;
	paintinfo.top = PageY(0, 0);
	paintinfo.bottom = PageY(INT_MAX, INT_MAX);
	paintinfo.indexentry = Null;
	paintinfo.hyperlink = Null;
	paintinfo.context = context;
	txt.Paint(*this, py, GetPageRect(), paintinfo);
	py = txt.GetHeight(py, GetPageRect());
	LLOG("Final pos: " << py);
	Page(py.page);
	y = py.y;
}
Example #13
0
void  DocOut::Qtf(const char *s) {
	QtfParser parser(s);
	for(;;) {
		switch(parser.Parse()) {
		case QtfParser::PARAGRAPH:
			Put(parser.GetParagraph());
			break;
		case QtfParser::TABLE:
			Put(parser.GetTable());
			break;
		case QtfParser::PAGE:
			Page();
			break;
		case QtfParser::END:
			return;
		}
	}
}
Example #14
0
void BufferManager::pageOut(int index) {
	// If page is dirty, write it to disk
	if (dirtied[index] == 1) {
		char buffer[4096] = {};
		char* pageBytes = (char*) &pages[index];
		for (int i = 0; i < 4096; i++) { buffer[i] = pageBytes[i]; }
		int blockOffset = getBlockOffset(pageNums[index]);
		fm->write(dbName, blockOffset, 8, buffer);
	}

	// Evict page
	pages[index] = Page();

	// Reset page status
	pageNums[index] = 0;
	dirtied[index] = 0;
	pinned[index] = 0;
}
Example #15
0
int caml_page_table_initialize(mlsize_t bytesize)
{
  uintnat pagesize = Page(bytesize);

  caml_page_table.size = 1;
  caml_page_table.shift = 8 * sizeof(uintnat);
  /* Aim for initial load factor between 1/4 and 1/2 */
  while (caml_page_table.size < 2 * pagesize) {
    caml_page_table.size <<= 1;
    caml_page_table.shift -= 1;
  }
  caml_page_table.mask = caml_page_table.size - 1;
  caml_page_table.occupancy = 0;
  caml_page_table.entries = calloc(caml_page_table.size, sizeof(uintnat));
  if (caml_page_table.entries == NULL)
    return -1;
  else
    return 0;
}
Example #16
0
bool InfoPane::RemoveNonLogger(wxWindow* p)
{
    for(int i = 0; i < num_pages; ++i)
    {
        if(page[i].window == p)
        {
            if(page[i].islogger)
            {
                cbThrow(_T("Bad API usage. Shame on you."));
            }

            RemovePage(GetPageIndex(page[i].window));
            page[i] = Page();
            return true;
        }
    }

   return false;
}
Example #17
0
void WebCrawler::processNewLinks(URL * newURLstoCrawl,int numOfURLs, URL & startURL)
{

		for(int I=0; I<numOfURLs; I++)
		{
			bool addToQueue = true;
			URL * newURL = new URL(newURLstoCrawl[I]); 
			if(!validator->isValid(newURLstoCrawl[I]))
				addToQueue = false;

			if(!validator->isInScope(newURLstoCrawl[I],startURL))
				addToQueue = false;

			string newContents; 

			try
			{
				newContents = downloader->download(newURLstoCrawl[I]);
			}
			catch(CS240Exception &e)
			{
				//skip the bad URL 
				delete newURL;
				continue;
			}
	
			
			Page dummyPage= Page("",newURLstoCrawl[I]);
			if(history->CheckHistory(&dummyPage))
				addToQueue = false;

			if(addToQueue == true)
			{
				string newDesc = parser->findDescription(newContents);
				Page * realPage = new Page(newDesc, newURLstoCrawl[I]);
				history->AddPage(realPage);
				queue->AddPage(realPage);
			}
			delete newURL;
		}

}
Example #18
0
int NewWizard::nextId() const
      {
      switch(Page(currentId())) {
            case Page::Type:
                  return int(Page::Template);
            case Page::Template: {
                  QString p = p4->templatePath();
                  QFileInfo fi(p);
                  if (fi.baseName() == "00-Blank")
                        return int(Page::Instruments);
                  return int(Page::Keysig);
                  }
            case Page::Instruments:
                  return int(Page::Keysig);
            case Page::Keysig:
                  return int(Page::Timesig);
            case Page::Timesig:
            default:
                  return int(Page::Invalid);
            }
      }
Example #19
0
int caml_page_table_lookup(void * addr)
{
#ifdef USE_STATIC_VMEM
  if (addr >= (void *)MAJOR_HEAP_BASE)
    return In_heap;
  else if (addr >= (void *)MINOR_HEAP_BASE)
    return In_young;
  else if ((unsigned long)addr >= mlstart && (unsigned long)addr < mlend)
    return In_static_data;
#endif
  uintnat h, e;

  h = Hash(Page(addr));
  /* The first hit is almost always successful, so optimize for this case */
  e = caml_page_table.entries[h];
  if (Page_entry_matches(e, (uintnat)addr)) return e & 0xFF;
  while(1) {
    if (e == 0) return 0;
    h = (h + 1) & caml_page_table.mask;
    e = caml_page_table.entries[h];
    if (Page_entry_matches(e, (uintnat)addr)) return e & 0xFF;
  }
}
Example #20
0
int NewWizard::nextId() const
      {
      int next;
      switch (Page(currentId())) {
            case Page::Type:
                  next = Page::Template;
                  break;
            case Page::Template:
                  next = emptyScore() ? Page::Instruments : Page::Keysig;
                  break;
            case Page::Instruments:
                  next = Page::Keysig;
                  break;
            case Page::Keysig:
                  next = Page::Timesig;
                  break;
            case Page::Timesig:
            default:
                  next = Page::Invalid;
                  break;
            }
      return next;
      }
Example #21
0
int caml_page_table_lookup(void * addr)
{
#ifdef USE_STATIC_VMEM
  if (addr >= HYPERVISOR_VIRT_END)
    return In_heap;
  if ((unsigned long)addr >= mlstart && (unsigned long)addr < mlend)
    return In_static_data;
  /* XXX need minor heap area also. In_code area is mapped to In_static_data. */
  return 0;
#else
  uintnat h, e;

  h = Hash(Page(addr));
  /* The first hit is almost always successful, so optimize for this case */
  e = caml_page_table.entries[h];
  if (Page_entry_matches(e, (uintnat)addr)) return e & 0xFF;
  while(1) {
    if (e == 0) return 0;
    h = (h + 1) & caml_page_table.mask;
    e = caml_page_table.entries[h];
    if (Page_entry_matches(e, (uintnat)addr)) return e & 0xFF;
  }
#endif
}
Example #22
0
Mapping::Page
Mapping::page() const
{
  return Page(data()->data.address);
}
Example #23
0
/* Allocate more memory from malloc for the heap.
   Return a block of at least the requested size (in words).
   Return NULL when out of memory.
*/
static char *expand_heap (mlsize_t request)
{
  char *mem;
  char *new_page_table = NULL;
  asize_t new_page_table_size = 0;
  asize_t malloc_request;
  asize_t i, more_pages;

  malloc_request = round_heap_chunk_size (Bhsize_wosize (request));
  gc_message ("Growing heap to %ldk\n",
	      (stat_heap_size + malloc_request) / 1024);
  mem = aligned_malloc (malloc_request + sizeof (heap_chunk_head),
                        sizeof (heap_chunk_head));
  if (mem == NULL){
    gc_message ("No room for growing heap\n", 0);
    return NULL;
  }
  mem += sizeof (heap_chunk_head);
  (((heap_chunk_head *) mem) [-1]).size = malloc_request;
  Assert (Wosize_bhsize (malloc_request) >= request);
  Hd_hp (mem) = Make_header (Wosize_bhsize (malloc_request), 0, Blue);

#ifndef SIXTEEN
  if (mem < heap_start){
    /* This is WRONG, Henning Niss 2005: */
    more_pages = -Page (mem);
  }else if (Page (mem + malloc_request) > page_table_size){
    Assert (mem >= heap_end);
    more_pages = Page (mem + malloc_request) - page_table_size;
  }else{
    more_pages = 0;
  }

  if (more_pages != 0){
    new_page_table_size = page_table_size + more_pages;
    new_page_table = (char *) malloc (new_page_table_size);
    if (new_page_table == NULL){
      gc_message ("No room for growing page table\n", 0);
      free (mem);
      return NULL;
    }
  }

  if (mem < heap_start){
    Assert (more_pages != 0);
    for (i = 0; i < more_pages; i++){
      new_page_table [i] = Not_in_heap;
    }
    bcopy (page_table, new_page_table + more_pages, page_table_size);
    (((heap_chunk_head *) mem) [-1]).next = heap_start;
    heap_start = mem;
  }else{
    char **last;
    char *cur;

    if (mem >= heap_end) heap_end = mem + malloc_request;
    if (more_pages != 0){
      for (i = page_table_size; i < new_page_table_size; i++){
        new_page_table [i] = Not_in_heap;
      }
      bcopy (page_table, new_page_table, page_table_size);
    }
    last = &heap_start;
    cur = *last;
    while (cur != NULL && cur < mem){
      last = &((((heap_chunk_head *) cur) [-1]).next);
      cur = *last;
    }
    (((heap_chunk_head *) mem) [-1]).next = cur;
    *last = mem;
  }

  if (more_pages != 0){
    free (page_table);
    page_table = new_page_table;
    page_table_size = new_page_table_size;
  }
#else                           /* Simplified version for the 8086 */
  {
    char **last;
    char *cur;

    last = &heap_start;
    cur = *last;
    while (cur != NULL && (char huge *) cur < (char huge *) mem){
      last = &((((heap_chunk_head *) cur) [-1]).next);
      cur = *last;
    }
    (((heap_chunk_head *) mem) [-1]).next = cur;
    *last = mem;
  }
#endif

  for (i = Page (mem); i < Page (mem + malloc_request); i++){
    page_table [i] = In_heap;
  }
  stat_heap_size += malloc_request;
  return Bp_hp (mem);
}
Example #24
0
/* Take a chunk of memory as argument, which must be the result of a
   call to [caml_alloc_for_heap], and insert it into the heap chaining.
   The contents of the chunk must be a sequence of valid blocks and
   fragments: no space between blocks and no trailing garbage.  If
   some blocks are blue, they must be added to the free list by the
   caller.  All other blocks must have the color [caml_allocation_color(mem)].
   The caller must update [caml_allocated_words] if applicable.
   Return value: 0 if no error; -1 in case of error.
*/
int caml_add_to_heap (char *m)
{
  asize_t i;
                                     Assert (Chunk_size (m) % Page_size == 0);
#ifdef DEBUG
  /* Should check the contents of the block. */
#endif /* debug */

  caml_gc_message (0x04, "Growing heap to %luk bytes\n",
                   (caml_stat_heap_size + Chunk_size (m)) / 1024);

  /* Extend the page table as needed. */
  if (Page (m) < caml_page_low){
    page_table_entry *block, *new_page_table;
    asize_t new_page_low = Page (m);
    asize_t new_size = caml_page_high - new_page_low;
    
    caml_gc_message (0x08, "Growing page table to %lu entries\n", new_size);
    block = malloc (new_size * sizeof (page_table_entry));
    if (block == NULL){
      caml_gc_message (0x08, "No room for growing page table\n", 0);
      return -1;
    }
    new_page_table = block - new_page_low;
    for (i = new_page_low; i < caml_page_low; i++){
      new_page_table [i] = Not_in_heap;
    }
    for (i = caml_page_low; i < caml_page_high; i++){
      new_page_table [i] = caml_page_table [i];
    }
    free (caml_page_table + caml_page_low);
    caml_page_table = new_page_table;
    caml_page_low = new_page_low;
  }
  if (Page (m + Chunk_size (m)) > caml_page_high){
    page_table_entry *block, *new_page_table;
    asize_t new_page_high = Page (m + Chunk_size (m));
    asize_t new_size = new_page_high - caml_page_low;
    
    caml_gc_message (0x08, "Growing page table to %lu entries\n", new_size);
    block = malloc (new_size * sizeof (page_table_entry));
    if (block == NULL){
      caml_gc_message (0x08, "No room for growing page table\n", 0);
      return -1;
    }
    new_page_table = block - caml_page_low;
    for (i = caml_page_low; i < caml_page_high; i++){
      new_page_table [i] = caml_page_table [i];
    }
    for (i = caml_page_high; i < new_page_high; i++){
      new_page_table [i] = Not_in_heap;
    }
    free (caml_page_table + caml_page_low);
    caml_page_table = new_page_table;
    caml_page_high = new_page_high;
  }

  /* Mark the pages as being in the heap. */
  for (i = Page (m); i < Page (m + Chunk_size (m)); i++){
    caml_page_table [i] = In_heap;
  }

  /* Chain this heap chunk. */
  {
    char **last = &caml_heap_start;
    char *cur = *last;

    while (cur != NULL && cur < m){
      last = &(Chunk_next (cur));
      cur = *last;
    }
    Chunk_next (m) = cur;
    *last = m;

    ++ caml_stat_heap_chunks;
  }

  /* Update the heap bounds as needed. */
  /* already done:   if (m < caml_heap_start) heap_start = m; */
  if (m + Chunk_size (m) > caml_heap_end) caml_heap_end = m + Chunk_size (m);

  caml_stat_heap_size += Chunk_size (m);
  if (caml_stat_heap_size > caml_stat_top_heap_size){
    caml_stat_top_heap_size = caml_stat_heap_size;
  }
  return 0;
}
Example #25
0
void TabletModel::newPage(string name) {
	pages.push_back(Page());
	int pageKey = pages.size()-1; 
	namesToPages[name] = pageKey; 
}
Example #26
0
void Factory::registerObjects()
{
    _objectBook["blender"] = Page([&]() { return dynamic_pointer_cast<BaseObject>(make_shared<Blender>(_root)); }, BaseObject::Category::MISC, "blender");
    _objectBook["camera"] = Page([&]() { return dynamic_pointer_cast<BaseObject>(make_shared<Camera>(_root)); }, BaseObject::Category::MISC, "camera");
    _objectBook["filter"] = Page([&]() { return dynamic_pointer_cast<BaseObject>(make_shared<Filter>(_root)); }, BaseObject::Category::MISC, "filter");
    _objectBook["geometry"] = Page([&]() { return dynamic_pointer_cast<BaseObject>(make_shared<Geometry>(_root)); }, BaseObject::Category::MISC, "Geometry");
    _objectBook["image"] = Page([&]() { return dynamic_pointer_cast<BaseObject>(make_shared<Image>(_root)); }, BaseObject::Category::IMAGE, "image");

    _objectBook["image_v4l2"] = Page(
        [&]() {
            shared_ptr<BaseObject> object;
            if (!_isScene)
                object = dynamic_pointer_cast<BaseObject>(make_shared<Image_V4L2>(_root));
            else
                object = dynamic_pointer_cast<BaseObject>(make_shared<Image>(_root));
            return object;
        },
        BaseObject::Category::IMAGE,
        "Video4Linux2 input device");

#if HAVE_FFMPEG
    _objectBook["image_ffmpeg"] = Page(
        [&]() {
            shared_ptr<BaseObject> object;
            if (!_isScene)
                object = dynamic_pointer_cast<BaseObject>(make_shared<Image_FFmpeg>(_root));
            else
                object = dynamic_pointer_cast<BaseObject>(make_shared<Image>(_root));
            return object;
        },
        BaseObject::Category::IMAGE,
        "video");
#endif

#if HAVE_GPHOTO
    _objectBook["image_gphoto"] = Page(
        [&]() {
            shared_ptr<BaseObject> object;
            if (!_isScene)
                object = dynamic_pointer_cast<BaseObject>(make_shared<Image_GPhoto>(_root));
            else
                object = dynamic_pointer_cast<BaseObject>(make_shared<Image>(_root));
            return object;
        },
        BaseObject::Category::IMAGE,
        "digital camera");
#endif

#if HAVE_SHMDATA
    _objectBook["image_shmdata"] = Page(
        [&]() {
            shared_ptr<BaseObject> object;
            if (!_isScene)
                object = dynamic_pointer_cast<BaseObject>(make_shared<Image_Shmdata>(_root));
            else
                object = dynamic_pointer_cast<BaseObject>(make_shared<Image>(_root));
            return object;
        },
        BaseObject::Category::IMAGE,
        "video through shared memory");
#endif

#if HAVE_OPENCV
    _objectBook["image_opencv"] = Page(
        [&]() {
            shared_ptr<BaseObject> object;
            if (!_isScene)
                object = dynamic_pointer_cast<BaseObject>(make_shared<Image_OpenCV>(_root));
            else
                object = dynamic_pointer_cast<BaseObject>(make_shared<Image>(_root));
            return object;
        },
        BaseObject::Category::IMAGE,
        "camera through opencv");
#endif

    _objectBook["mesh"] = Page([&]() { return dynamic_pointer_cast<BaseObject>(make_shared<Mesh>(_root)); });

#if HAVE_SHMDATA
    _objectBook["mesh_shmdata"] = Page(
        [&]() {
            shared_ptr<BaseObject> object;
            if (!_isScene)
                object = dynamic_pointer_cast<BaseObject>(make_shared<Mesh_Shmdata>(_root));
            else
                object = dynamic_pointer_cast<BaseObject>(make_shared<Mesh>(_root));
            return object;
        },
        BaseObject::Category::MESH,
        "mesh through shared memory");
#endif

    _objectBook["object"] = Page([&]() { return dynamic_pointer_cast<BaseObject>(make_shared<Object>(_root)); }, BaseObject::Category::MISC, "object");

#if HAVE_PYTHON
    _objectBook["python"] = Page([&]() { return dynamic_pointer_cast<BaseObject>(make_shared<PythonEmbedded>(_root)); }, BaseObject::Category::MISC, "python");
#endif

    _objectBook["queue"] = Page(
        [&]() {
            shared_ptr<BaseObject> object;
            if (!_isScene)
                object = dynamic_pointer_cast<BaseObject>(make_shared<Queue>(_root));
            else
                object = dynamic_pointer_cast<BaseObject>(make_shared<QueueSurrogate>(_root));
            return object;
        },
        BaseObject::Category::IMAGE,
        "video queue");

    _objectBook["texture_image"] = Page([&]() { return dynamic_pointer_cast<BaseObject>(make_shared<Texture_Image>(_root)); }, BaseObject::Category::MISC, "texture image");

#if HAVE_OSX
    _objectBook["texture_syphon"] =
        Page([&]() { return dynamic_pointer_cast<BaseObject>(make_shared<Texture_Syphon>(_root)); }, BaseObject::Category::IMAGE, "texture image through Syphon");
#endif

    _objectBook["warp"] = Page([&]() { return dynamic_pointer_cast<BaseObject>(make_shared<Warp>(_root)); }, BaseObject::Category::MISC, "warp");
    _objectBook["window"] = Page([&]() { return dynamic_pointer_cast<BaseObject>(make_shared<Window>(_root)); }, BaseObject::Category::MISC, "window");
}
Example #27
0
void DocReport::SkipAfter(int cy) {
	ypos += cy;
	if(ypos > GetYLim())
		Page();
}
Example #28
0
void
TrussPrintout::OnPreparePrinting() {
    int page_width, page_height;
    int current_page_y = 0;
    GetPageSizePixels(&page_width, &page_height);
    wxDC *dc = GetDC();
    
    int printer_x, printer_y, screen_x, screen_y;
    GetPPIPrinter(&printer_x, &printer_y);
    GetPPIScreen(&screen_x, &screen_y);
    float scale = printer_x / (float)screen_x;
    
    // Use a 12pt font. For some reason wxFont doesn't use real points, so
    // we still have to scale it.
    wxFont &font = *wxTheFontList->FindOrCreateFont(
        12 * scale, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL,
        wxFONTWEIGHT_NORMAL
    );
    dc->SetFont(font);
    
    // Margins:
    int ml, mt, mr, mb;
    int widthmm, heightmm;
    GetPageSizeMM(&widthmm, &heightmm);
    double one_mm_px = page_width / (double)widthmm;
    
    wxPoint margintl = page_setup_dialog_data->GetMarginTopLeft();
    wxPoint marginbr = page_setup_dialog_data->GetMarginBottomRight();
    
    ml = margintl.x * one_mm_px;
    mt = margintl.y * one_mm_px;
    mr = marginbr.x * one_mm_px;
    mb = marginbr.y * one_mm_px;
        
    page_height -= mt + mb;
    page_width -= ml + mr;
    
    for (int i = 0; i < printitems.size(); ++i) {
        if (printitems[i]->isbreak()) {
            PageBreak *pb = static_cast<PageBreak *>(printitems[i]);
            
            // Add room for the page header/title.
            current_page_y = get_text_height(*dc, pb->header);
            
            pages.push_back(Page(pb->header, ml, mt, mr, mb));
            
            delete pb;
        } else {
            Truss *truss = static_cast<TrussContainer *>(printitems[i])->truss;
            
            int truss_height_px = truss->getHeight() * page_width
                                  / (60.0 * 12.0);
            int total_height = truss_height_px
                               + get_text_height(*dc, truss->gettext());
            
            if (!truss->getnotes().empty()) {
                total_height += get_text_height(*dc, truss->getnotes());
                // Add the 1/2 line padding in between title and notes
                total_height += get_text_height(*dc, wxT("X")) / 2;
            }
                        
            if (current_page_y + total_height > page_height) {
                current_page_y = get_text_height(*dc, "continuation...");
                pages.push_back(Page("continuation...", ml, mt, mr, mb));
            }
            
            pages.back().add(truss);
            
            current_page_y += total_height;
            // Add 3 blank lines of padding before the next truss.
            current_page_y += get_text_height(*dc, wxT("X")) * 3;
            
            delete static_cast<TrussContainer *>(printitems[i]);
        }
    }
    
    printitems.clear();
}
Example #29
0
void KernelStart(char *cmd_args[], unsigned int pmem_size, UserContext *uctxt) {
	//mark the initial KernelBrk
	KernelBrk = KernelDataEnd;

	//FreeFrameCount is only used page_table.c
	FreeFrameCount = pmem_size / PAGESIZE;

	ipc_table = (ObjectNode **) malloc(sizeof(ObjectNode *) * HASH_LEN);
	if (NULL == ipc_table) {
		TracePrintf(0, "ipc_table cannot be initialized!\n");
		return;
	}
	memset(ipc_table, 0, sizeof(ObjectNode *) * HASH_LEN);

	ReadyQueue	= (Queue *) malloc(sizeof(Queue));
	DelayQueue	= (Queue *) malloc(sizeof(Queue));
	if (NULL == ReadyQueue) {
		TracePrintf(0, "ReadyQueue cannot be initialized!\n");
		return;
	}
	if (NULL == DelayQueue) {
		TracePrintf(0, "DelayQueue cannot be initialized!\n");
		return;
	}

	memset(ReadyQueue,	0, sizeof(Queue));
	memset(DelayQueue,	0, sizeof(Queue));

	u_int i;
	for (i = 0; i < NUM_TERMINALS; i++) {
		BufferQueue[i]		= (Queue *) malloc(sizeof(Queue));
		ReceiveQueue[i]		= (Queue *) malloc(sizeof(Queue));
		TransmitQueue[i]	= (Queue *) malloc(sizeof(Queue));
		if (NULL == BufferQueue[i]) {
			TracePrintf(0, "BufferQueue[%d] cannot be initialized!\n", i);
			return;
		}
		if (NULL == ReceiveQueue[i]) {
			TracePrintf(0, "ReceiveQueue[%d] cannot be initialized!\n", i);
			return;
		}
		if (NULL == TransmitQueue[i]) {
			TracePrintf(0, "TransmitQueue[%d] cannot be initialized!\n", i);
			return;
		}


		memset(BufferQueue[i], 0, sizeof(Queue));
		memset(ReceiveQueue[i], 0, sizeof(Queue));
		memset(TransmitQueue[i], 0, sizeof(Queue));
	}

	//create interrupt vector table in kernel
	void **interruptVectorTable =
			 (void **) malloc(sizeof(void *) * TRAP_VECTOR_SIZE);
	if (NULL == interruptVectorTable) {
		TracePrintf(0, "Interrupt Vector Table cannot be initialized!\n");
		return;
	}

	//fill each entry in table with pointer to correct handler
	interruptVectorTable[TRAP_KERNEL] 	= &TrapKernelHandler;
	interruptVectorTable[TRAP_CLOCK] 	= &TrapClockHandler;
	interruptVectorTable[TRAP_ILLEGAL] 	= &TrapIllegalHandler;
	interruptVectorTable[TRAP_MEMORY] 	= &TrapMemoryHandler;
	interruptVectorTable[TRAP_MATH] 	= &TrapMathHandler;
	interruptVectorTable[TRAP_TTY_RECEIVE] 	= &TrapTtyReceiveHandler;
	interruptVectorTable[TRAP_TTY_TRANSMIT]	= &TrapTtyTransmitHandler;
	interruptVectorTable[TRAP_DISK] 	= &TrapDiskHandler;
	for (i = 8; i < 16; i++) {
		interruptVectorTable[i] 	= &TrapErrorHandler;
	}	

	//point REG_VECTOR_BASE to interrupt vector table
	WriteRegister(REG_VECTOR_BASE, (u_int) interruptVectorTable);
	TracePrintf(0, "Interrupt vector table initialization completed.\n");

	//Build page table for Region 0
	KernelPageTable = (PTE *) malloc(sizeof(PTE) * MAX_PT_LEN);
	if (NULL == KernelPageTable) {
		TracePrintf(0, "KernelPageTable cannot be initialized!\n");
		return;
	}
	memset(KernelPageTable, 0, sizeof(PTE) * MAX_PT_LEN);

	TracePrintf(0, "Page tables built successfully.\n");

	//create kernel stack union
	KS = (KernelStack *) KERNEL_STACK_BASE;
	TracePrintf(0, "Kernel stack initialization completed.\n");

	//build input init process PCB
	KS->CurrentPCB = InitPCB = InitializePCB();
	if (NULL == InitPCB) {
		TracePrintf(0, "InitPCB cannot be initialized!\n");
		return;
	}

	// We enablePTE after using all the malloc in the kernel because
	// only in this way we can make sure the getFreeFrame will be called
	// and update the FreeFrameCount.
	enablePTE(0, Page(KernelDataStart), PROT_READ | PROT_EXEC);
	enablePTE(Page(KernelDataStart), Page(KernelBrk), PROT_READ | PROT_WRITE);
	enablePTE(INTERFACE, Page(KERNEL_STACK_LIMIT), PROT_READ | PROT_WRITE);

	// initialize virtual memory registers
	WriteRegister(REG_PTBR0, (u_int) KernelPageTable);
	WriteRegister(REG_PTLR0, MAX_PT_LEN);
	WriteRegister(REG_PTBR1, (u_int) KS->CurrentPCB->pagetable);
	WriteRegister(REG_PTLR1, MAX_PT_LEN);
	TracePrintf(0, "Table information loading to hardware completed.\n");

	//set up the link list to keep track of free frames
	//from KernelBrk to KERNEL_STACK_BASE
	*FrameNumber(INTERFACE) = Page(KernelBrk);
	for (i = Page(KernelBrk); i < INTERFACE - 1; i++) {
		*FrameNumber(i) = i + 1;
	}
	*FrameNumber(INTERFACE - 1) = Page(VMEM_0_LIMIT);
	for (i = Page(VMEM_0_LIMIT); i < Page(pmem_size - 1); i++) {
		*FrameNumber(i) = i + 1;
	}
	TracePrintf(0, "Free frames' linked list has been set up.\n");

	//enable virtual memory
	WriteRegister(REG_VM_ENABLE, 1);
	VM_ENABLED = 1;
	TracePrintf(0, "Virtual memory has been enabled.\n");

	TracePrintf(0, "Load input program. (Default init)\n");
	if (NULL != cmd_args[0]) {
		if (FAILURE == LoadProgram(cmd_args[0], cmd_args, InitPCB)) {
			TracePrintf(0, "Load input program failed!\n");
			return;
		}
	} else {
		char *args[] = {"init", NULL};
		if (FAILURE == LoadProgram(args[0], args, InitPCB)) {
			TracePrintf(0, "Load input program failed!\n");
			return;
		}
	}

	TracePrintf(0, "Build the Idle process.\n");
	//build kernel idle process PCB
	IdlePCB = InitializePCB();
	if (NULL == IdlePCB) {
		TracePrintf(0, "IdlePCB cannot be initialized!\n");
		return;
	}

	//sp = virtual address of top of stack
	IdlePCB->uctxt.sp  = (void *) (VMEM_1_LIMIT
				     - INITIAL_STACK_FRAME_SIZE
				     - POST_ARGV_NULL_SPACE);
	//pc = virtual address of DoIdle function
	IdlePCB->uctxt.pc  = &DoIdle;

	//enable user stack for idle process	
	IdlePCB->pagetable[MAX_PT_LEN - 1].valid = 1;
	IdlePCB->pagetable[MAX_PT_LEN - 1].prot = PROT_READ | PROT_WRITE;

	if (0 == FreeFrameCount) {
		TracePrintf(0, "No frame for Idle process pagetable!\n");
		return;
	}

	IdlePCB->pagetable[MAX_PT_LEN - 1].pfn = getFreeFrame(0);

	//use MyKCS initialize IdlePCB's KC and KS
	KernelContextSwitch(KCKSInit, (void *) IdlePCB, NULL);
	TracePrintf(0, "How many time will this line be printed?\n");

	//copy current context into hardware provided context
	*uctxt = KS->CurrentPCB->uctxt;

	TracePrintf(0, "KernelStart finished.\n");
}
Example #30
0
int main(void) {

  consoleDemoInit();

  //videoSetMode(MODE_FB0);
  videoSetMode( MODE_5_2D );
  vramSetBankA(VRAM_A_MAIN_BG);
  vramSetBankB(VRAM_B_MAIN_BG);
  // vramSetBankC(VRAM_C_MAIN_BG);
  // vramSetBankD(VRAM_D_MAIN_BG_0x06040000);
  int bg = bgInit(3, BgType_Bmp8, BgSize_B8_512x512, 0,0);  //vramSetBankA(VRAM_A_LCD);

  lcdMainOnBottom();
  // lcdMainOnTop();

  printf("Video modes configured\n");
  printf("BG ID %d\n", bg);

  if (fatInitDefault())
    printf("FAT initialized\n");
  else
    printf("FAT initialization failed\n");

  AppState state;
  uiOpenNotebook(state);

  // Keyboard *kbd =  keyboardDemoInit();

  Segment * currentSegment = NULL;


  touchPosition touch;

  while (1) {
    scanKeys();
    
    if(keysHeld() & KEY_TOUCH)
      {
	// write the touchscreen coordinates in the touch variable
	touchRead(&touch);
	
	Point screenPoint = Point(touch.px, touch.py);
	Point imagePoint = state.convertScreenToImage(screenPoint);

	if (currentSegment == NULL) {
	  state.currentPage->segments.push_back(Segment());
	  currentSegment = &(state.currentPage->segments[state.currentPage->segments.size()-1]);
	  currentSegment->points.push_back(imagePoint);
	  continue;
	}

	Point lastImagePoint = currentSegment->points[currentSegment->points.size()-1];
	currentSegment->points.push_back(imagePoint);

	Point bufferPoint = state.convertScreenToBuffer(screenPoint);
	Point lastBufferPoint = state.convertImageToBuffer(lastImagePoint);
	drawLine(lastBufferPoint.x, lastBufferPoint.y,  bufferPoint.x, bufferPoint.y, RGB15(31,0,0) | BIT(15));
      }    
    else {
      currentSegment = NULL;
    }
    if (keysDown() & KEY_X) {
      int page = state.lastPage+1;
      while (state.notebook.pages.size() < page+1) {
	state.notebook.pages.push_back(Page());
	printf("New Page created\n");
      }
      state.currentPage = &(state.notebook.pages[page]);
      currentSegment = NULL;

      printf("Display page %d\n", page);

      fillDisplay(RGB15(0,0,0) | BIT(15), page, state);
      drawPage(state.currentPage, RGB15(31,0,0) | BIT(15), state);
    }
    if (keysDown() & KEY_Y) {
      int page = 0;
      if (state.lastPage > 0) {
	page = state.lastPage-1;
      }
      state.currentPage = &(state.notebook.pages[page]);
      currentSegment = NULL;

      printf("Display page %d\n", page);

      fillDisplay(RGB15(0,0,0) | BIT(15), page, state);
      drawPage(state.currentPage, RGB15(31,0,0) | BIT(15), state);
    }
    if (keysDown() & KEY_A) {
      int page = 0;
      std::string fileName = state.notebookName + "/notes.txt";
      state.notebook = loadFile(fileName.c_str());

      state.currentPage = &(state.notebook.pages[page]);
      currentSegment = NULL;

      printf("Display page %d\n", page);

      fillDisplay(RGB15(0,0,0) | BIT(15), page, state);
      drawPage(state.currentPage, RGB15(31,0,0) | BIT(15), state);
    }
    if (keysDown() & KEY_B) {
      std::string fileName = state.notebookName + "/notes.txt";
      saveFile(fileName.c_str(), state.notebook);
    }
    if (keysDown() & KEY_LEFT) {
      state.scroll_x-=50;
      updateCenter(state);
    }
    if (keysDown() & KEY_RIGHT) {
      state.scroll_x+=50;
      updateCenter(state);
    }
    if (keysDown() & KEY_UP) {
      state.scroll_y-=50;
      updateCenter(state);
    }
    if (keysDown() & KEY_DOWN) {
      state.scroll_y+=50;
      updateCenter(state);
    }
    if (keysDown() & KEY_START) {
      uiOpenNotebook(state);
    }

    swiWaitForVBlank();
  }
}