Esempio n. 1
0
 TreeNode *util(ListNode *head, ListNode *end) {
     if (head == end)
         return NULL;
     ListNode *fast, *mid;
     fast = mid = head;
     while (fast->next != end && fast->next->next != end) {
         fast = fast->next->next;
         mid = mid->next;
     }
     TreeNode *root = new TreeNode(mid->val);
     root->left = util(head, mid);
     root->right = util(mid->next, end);
     return root;
 }
void UBDesktopAnnotationController::windowCapture()
{
    mIsFullyTransparent = true;
    updateBackground();

    mDesktopPalette->disappearForCapture();

    UBWindowCapture util(this);

    if (util.execute() == QDialog::Accepted)
    {
        QPixmap windowPixmap = util.getCapturedWindow();

        // on Mac OS X we can only know that user cancel the operatiion by checking is the image is null
        // because the screencapture utility always return code 0 event if user cancel the application
        if (!windowPixmap.isNull())
        {
            emit imageCaptured(windowPixmap, false);
        }
    }

    mDesktopPalette->appear();

    mIsFullyTransparent = false;

    updateBackground();
}
Esempio n. 3
0
int SaveSetting::save_setting(QString fileName, QString fileTitle, int m_postion, int playState)
{
    //qDebug()<<"save setting................";
    FileListUtil util(fileName, this, fileTitle);
    QStringList List, ListPlayInfo;
    List.append(QString("%1").arg(s_listinfo.province));
    List.append(QString("%1").arg(s_listinfo.city));
    List.append(QString("%1").arg(s_listinfo.maker));
    List.append(QString("%1").arg(s_listinfo.model));
    List.append(QString("%1").arg(s_listinfo.termed));
    List.append(QString("%1").arg(s_listinfo.VIN));
    List.append(QString("%1").arg(s_listinfo.platecolor));
    List.append(QString("%1").arg(s_listinfo.plate));
    List.append(QString("%1").arg(s_listinfo.platetype));
    List.append(QString("%1").arg(s_listinfo.installtime));
    List.append(QString("%1").arg(s_listinfo.mileage));
    List.append(QString("%1").arg(s_listinfo.rate));
    List.append(QString("%1").arg(s_listinfo.sensingelement));
    List.append(QString("%1").arg(s_listinfo.phone));
    List.append(QString("%1").arg(s_listinfo.auth));
    List.append(QString("%1").arg(s_listinfo.main));
    List.append(QString("%1").arg(s_listinfo.second));
    List.append(QString("%1").arg(s_listinfo.port));
    List.append(QString("%1").arg(s_listinfo.speed));
    List.append(QString("%1").arg(s_listinfo.drivedura));
    List.append(QString("%1").arg(s_listinfo.terminaltype));
    List.append(QString("%1").arg(s_listinfo.hadversion));

    ListPlayInfo.append(QString("%1").arg(s_listinfo.province));
    util.saveFileListOther(List, ListPlayInfo,base_setting);
    return 1;
}
Esempio n. 4
0
void
LoadInfo::ComputeIsThirdPartyContext(nsPIDOMWindow* aOuterWindow)
{
  nsContentPolicyType type =
    nsContentUtils::InternalContentPolicyTypeToExternal(mInternalContentPolicyType);
  if (type == nsIContentPolicy::TYPE_DOCUMENT) {
    // Top-level loads are never third-party.
    mIsThirdPartyContext = false;
    return;
  }

  nsPIDOMWindow* win = aOuterWindow;
  if (type == nsIContentPolicy::TYPE_SUBDOCUMENT) {
    // If we're loading a subdocument, aOuterWindow points to the new window.
    // Check if its parent is third-party (and then we can do the same check for
    // it as we would do for other sub-resource loads.

    win = aOuterWindow->GetScriptableParent();
    MOZ_ASSERT(win);
  }

  nsCOMPtr<mozIThirdPartyUtil> util(do_GetService(THIRDPARTYUTIL_CONTRACTID));
  if (NS_WARN_IF(!util)) {
    return;
  }

  util->IsThirdPartyWindow(win, nullptr, &mIsThirdPartyContext);
}
Esempio n. 5
0
Task::Task(const std::string& record)
: name(""), slots("1")
{
	nextTask[passed] = "";
	nextTask[redirect] = "";
 
	pNextTask[passed] = nullptr;
	pNextTask[redirect] = nullptr;
 
	Utilities util(field_width);
 
	size_t pos = 0;
	bool more = true;
 
	name = util.nextToken(record, pos, more);
	if (!name.empty())
	{
		if (more)
			slots = util.nextToken(record, pos, more);
 
		if (more)
			nextTask[passed] = util.nextToken(record, pos, more);
 
		if (more)
			nextTask[redirect] = util.nextToken(record, pos, more);	
 
		if (util.getFieldWidth() < LIMIT_WIDTH)
			field_width = util.getFieldWidth();
	}
}
Esempio n. 6
0
void callsubs (int niter)
{
  callutil10times ();
  callutil100times ();
  A();
  util ();
}
Esempio n. 7
0
File: edf-wm.c Progetto: Aand1/ROSCH
/**
 * return the time length by jiffies, during which DBF should be tested 
 * on the give CPU.
 * the global list must be locked.
 */
static unsigned long dbf_len(int cpu, resch_task_t *rt)
{
	resch_task_t *p;
	unsigned long x = 0, u = 0, d = 0;

	/* compute for tasks assigned to @cpu. */
	p = global_highest_prio_task();
	while (p) {
		if (split_is_on_cpu(p, cpu)) {
			x += max_ulong(0, p->period - edf_wm_task[p->rid].deadline) * 
				util_split(p, cpu);
			u += util_split(p, cpu);
			d = max_ulong(d, edf_wm_task[p->rid].deadline);
		}
		else if (task_is_on_cpu(p, cpu)) {
			x += max_ulong(0, p->period - p->deadline) * util(p);
			u += util(p);
			d = max_ulong(d, p->deadline);
		}
		p = global_next_prio_task(p);
	}

	/* compute for @rt. */
	if (split_is_on_cpu(rt, cpu)) {
		unsigned long deadline = edf_wm_task[rt->rid].deadline;
		x += max_ulong(0, rt->period - deadline) * util_split(rt, cpu);
		u += util_split(rt, cpu);
		d = max_ulong(d, deadline);
	}
	else {
		x += max_ulong(0, rt->period - rt->deadline) * util(rt);
		u += util(rt);
		d = max_ulong(d, rt->deadline);
	}

	/* if total utilization is equal to 100%, just return the max deadline.
	   dbf_test() will anyway reject the given task. */
	if (100 == u) {
		return d;
	}
	else if (100 < u) {
		return 0;
	}
	else {
		return max_ulong(x / (100 - u), d);
	}
}
Esempio n. 8
0
 bool isSymmetric(TreeNode* root) {
     // Solution 1
     /*
     if(!root) return true;
     
     queue<TreeNode*> ql;
     queue<TreeNode*> qr;
     
     TreeNode *nl;
     TreeNode *nr;
     
     ql.push(root->left);
     qr.push(root->right);
     
     while(!ql.empty() && !qr.empty()) {
         nl = ql.front();
         nr = qr.front();
         
         ql.pop();
         qr.pop();
         
         if(!nl && !nr) continue;
         if(!nl || !nr) return false;
         if(nl->val != nr->val) return false;
         
         ql.push(nl->left);
         ql.push(nl->right);
         qr.push(nr->right);
         qr.push(nr->left);
     }
     return true;
     */
     //Solution 2
     /*
     if(!root) return true;
     
     queue<TreeNode*> que;
     que.push(root->left);
     que.push(root->right);
     
     while(!que.empty()) {
         TreeNode* left = que.front();
         que.pop();
         TreeNode* right = que.front();
         que.pop();
         if(!left && !right) continue;
         if(!left || !right) return false;
         if(left->val != right->val) return false;
         que.push(left->left);
         que.push(right->right); // the sequence of node pushed here differs from  that of Solution 1
         que.push(left->right);
         que.push(right->left);
     }
     return true;
     */
     // Solution 3
     if(!root) return true;
     return util(root->left, root->right);
 }
Esempio n. 9
0
  void DatabaseIO::create_path(const std::string &filename) const
  {
    bool               error_found = false;
    std::ostringstream errmsg;

    if (myProcessor == 0) {
      Ioss::FileInfo file = Ioss::FileInfo(filename);
      std::string    path = file.pathname();

      const int mode = 0777; // Users umask will be applied to this.

      auto iter = path.begin();
      while (iter != path.end() && !error_found) {
        iter                  = std::find(iter, path.end(), '/');
        std::string path_root = std::string(path.begin(), iter);

        if (iter != path.end()) {
          ++iter; // Skip past the '/'
        }

        if (path_root.empty()) { // Path started with '/'
          continue;
        }

        struct stat st;
        if (stat(path_root.c_str(), &st) != 0) {
          if (mkdir(path_root.c_str(), mode) != 0 && errno != EEXIST) {
            errmsg << "ERROR: Cannot create directory '" << path_root
                   << "' : " << std::strerror(errno) << "\n";
            error_found = true;
          }
        }
        else if (!S_ISDIR(st.st_mode)) {
          errno = ENOTDIR;
          errmsg << "ERROR: Path '" << path_root << "' is not a directory.\n";
          error_found = true;
        }
      }
    }
    else {
      // Give the other processors something to say in case there is an error.
      errmsg << "ERROR: Could not create path. See processor 0 output for more "
                "details.\n";
    }

    // Sync all processors with error status...
    // All processors but 0 will have error_found=false
    // Processor 0 will have error_found = true or false depending on path
    // result.
    int is_error = error_found ? 1 : 0;
    error_found  = (util().global_minmax(is_error, Ioss::ParallelUtils::DO_MAX) == 1);

    if (error_found) {
      IOSS_ERROR(errmsg);
    }
  }
Esempio n. 10
0
int
main(int argc, char *argv[])
{
    int      subtest, nsubtests;
    bool     test[N_TESTS];
    TestUtil util(argc, argv, "Tests RemoteProcess class");

    // Test the RemoteProcess class with a bad hostname.
    test[0] = Run_Test1(util.verbose, &subtest, &nsubtests);
    util.PrintTestResult(1, subtest, nsubtests, test[0]);
    
    return util.PassFail(test, N_TESTS);
}
Esempio n. 11
0
int
main(int argc, char *argv[])
{
    int      subtest, nsubtests;
    bool     test[N_TESTS];
    TestUtil util(argc, argv, "Tests the ColorAttributeList class.");

    // Test the Plot class.
    test[0] = Run_Test1(util.verbose, &subtest, &nsubtests);
    util.PrintTestResult(1, subtest, nsubtests, test[0]);

    return util.PassFail(test, N_TESTS);
}
Esempio n. 12
0
 Z3_ast Z3_API Z3_mk_atmost(Z3_context c, unsigned num_args, 
                            Z3_ast const args[], unsigned k) {
     Z3_TRY;
     LOG_Z3_mk_atmost(c, num_args, args, k);
     RESET_ERROR_CODE();
     parameter param(k);
     pb_util util(mk_c(c)->m());
     ast* a = util.mk_at_most_k(num_args, to_exprs(args), k);
     mk_c(c)->save_ast_trail(a);
     check_sorts(c, a);
     RETURN_Z3(of_ast(a));
     Z3_CATCH_RETURN(0);
 }
Esempio n. 13
0
  AxisAlignedBoundingBox DatabaseIO::get_bounding_box(const Ioss::ElementBlock *eb) const
  {
    if (elementBlockBoundingBoxes.empty()) {
      // Calculate the bounding boxes for all element blocks...
      std::vector<double> coordinates;
      Ioss::NodeBlock *   nb = get_region()->get_node_blocks()[0];
      nb->get_field_data("mesh_model_coordinates", coordinates);
      ssize_t nnode = nb->get_property("entity_count").get_int();
      ssize_t ndim  = nb->get_property("component_degree").get_int();

      Ioss::ElementBlockContainer element_blocks = get_region()->get_element_blocks();
      size_t                      nblock         = element_blocks.size();
      std::vector<double>         minmax;
      minmax.reserve(6 * nblock);

      for (auto &block : element_blocks) {
        double xmin, ymin, zmin, xmax, ymax, zmax;
        if (block->get_database()->int_byte_size_api() == 8) {
          std::vector<int64_t> connectivity;
          block->get_field_data("connectivity_raw", connectivity);
          calc_bounding_box(ndim, nnode, coordinates, connectivity, xmin, ymin, zmin, xmax, ymax,
                            zmax);
        }
        else {
          std::vector<int> connectivity;
          block->get_field_data("connectivity_raw", connectivity);
          calc_bounding_box(ndim, nnode, coordinates, connectivity, xmin, ymin, zmin, xmax, ymax,
                            zmax);
        }

        minmax.push_back(xmin);
        minmax.push_back(ymin);
        minmax.push_back(zmin);
        minmax.push_back(-xmax);
        minmax.push_back(-ymax);
        minmax.push_back(-zmax);
      }

      util().global_array_minmax(minmax, Ioss::ParallelUtils::DO_MIN);

      for (size_t i = 0; i < element_blocks.size(); i++) {
        Ioss::ElementBlock *   block = element_blocks[i];
        const std::string &    name  = block->name();
        AxisAlignedBoundingBox bbox(minmax[6 * i + 0], minmax[6 * i + 1], minmax[6 * i + 2],
                                    -minmax[6 * i + 3], -minmax[6 * i + 4], -minmax[6 * i + 5]);
        elementBlockBoundingBoxes[name] = bbox;
      }
    }
    return elementBlockBoundingBoxes[eb->name()];
  }
Esempio n. 14
0
Box method(Box **arr,int i,int l,string s1, string s2){
	int m=0,n=s1.length();
	Box b1;
	for(m=i;m<l;m++){
		Box b2;
		b2=util(s2[m],arr[i][n-m-1],arr[m+1][n-l-1]);
		b1.T+=b2.T;
		b1.F+=b2.F;
		b1.T%=1003;
		b1.F%=1003;

	}
	return b1;
}
Esempio n. 15
0
void decl_collector::visit(ast* n) {
    datatype_util util(m());
    m_todo.push_back(n);
    while (!m_todo.empty()) {
        n = m_todo.back();
        m_todo.pop_back();
        if (!m_visited.is_marked(n)) {
            switch(n->get_kind()) {
            case AST_APP: {
                app * a = to_app(n);
                for (expr* arg : *a) {
                    m_todo.push_back(arg);
                }
                m_todo.push_back(a->get_decl());
                break;
            }
            case AST_QUANTIFIER: {
                quantifier * q = to_quantifier(n);
                unsigned num_decls = q->get_num_decls();
                for (unsigned i = 0; i < num_decls; ++i) {
                    m_todo.push_back(q->get_decl_sort(i));
                }
                m_todo.push_back(q->get_expr());
                for (unsigned i = 0; i < q->get_num_patterns(); ++i) {
                    m_todo.push_back(q->get_pattern(i));
                }
                break;
            }
            case AST_SORT: 
                visit_sort(to_sort(n));
                break;
            case AST_FUNC_DECL: {
                func_decl * d = to_func_decl(n);
                for (sort* srt : *d) {
                    m_todo.push_back(srt);
                }
                m_todo.push_back(d->get_range());
                visit_func(d);
                break;
            }
            case AST_VAR:
                break;
            default:
                UNREACHABLE();
            }
            m_visited.mark(n, true);
        }
    }
}
Esempio n. 16
0
 Z3_ast Z3_API Z3_mk_pbeq(Z3_context c, unsigned num_args, 
                          Z3_ast const args[], int _coeffs[],
                          int k) {
     Z3_TRY;
     LOG_Z3_mk_pble(c, num_args, args, _coeffs, k);
     RESET_ERROR_CODE();
     pb_util util(mk_c(c)->m());
     vector<rational> coeffs;
     for (unsigned i = 0; i < num_args; ++i) {
         coeffs.push_back(rational(_coeffs[i]));
     }
     ast* a = util.mk_eq(num_args, coeffs.c_ptr(), to_exprs(args), rational(k));
     mk_c(c)->save_ast_trail(a);
     check_sorts(c, a);
     RETURN_Z3(of_ast(a));
     Z3_CATCH_RETURN(0);
 }
Esempio n. 17
0
void
LoadInfo::ComputeIsThirdPartyContext(nsPIDOMWindow* aOuterWindow)
{
  nsContentPolicyType type =
    nsContentUtils::InternalContentPolicyTypeToExternal(mInternalContentPolicyType);
  if (type == nsIContentPolicy::TYPE_DOCUMENT) {
    // Top-level loads are never third-party.
    mIsThirdPartyContext = false;
    return;
  }

  nsCOMPtr<mozIThirdPartyUtil> util(do_GetService(THIRDPARTYUTIL_CONTRACTID));
  if (NS_WARN_IF(!util)) {
    return;
  }

  util->IsThirdPartyWindow(aOuterWindow, nullptr, &mIsThirdPartyContext);
}
Esempio n. 18
0
File: edf-wm.c Progetto: Aand1/ROSCH
static unsigned long util_cpu(int cpu)
{
	resch_task_t *p;
	unsigned long u = 0;

	/* compute for tasks assigned to @cpu. */
	p = global_highest_prio_task();
	while (p) {
		if (split_is_on_cpu(p, cpu)) {
			u += util_split(p, cpu);
		}
		else if (task_is_on_cpu(p, cpu)) {
			u += util(p);
		}
		p = global_next_prio_task(p);
	}

	return u;
}
int cond::SchemaManager::execute(){

  bool drop= hasOptionValue("drop");
  bool dropAll= hasOptionValue("dropAll");
  bool create= hasOptionValue("create");
  std::string payloadName("");
  if( hasOptionValue("payload") ) payloadName = getOptionValue<std::string>("payload");
  std::string typeName("");
  if( hasOptionValue("type") ) typeName = getOptionValue<std::string>("type");

  cond::DbSession session = openDbSession("connect", Auth::COND_ADMIN_ROLE);

  cond::IOVSchemaUtility util( session, std::cout );

  cond::DbScopedTransaction trans( session );

  if( dropAll ){
    trans.start(false);
    util.dropAll();
    trans.commit();
    return 0;
  }

  if( drop || create ){
    trans.start(false);
    if( drop ){
      if(payloadName.empty()){
	throw cond::Exception("Payload name not provided.");
      }
      util.dropPayloadContainer( payloadName );
    }
    if( create ){
      util.createIOVContainer();
      if(!payloadName.empty()) util.createPayloadContainer( payloadName, typeName );
    }
    trans.commit();
    return 0;
  }
  
  throw cond::Exception("Option create or drop not provided.");
}
Esempio n. 20
0
 void table_base::to_formula(relation_signature const& sig, expr_ref& fml) const {
     // iterate over rows and build disjunction
     ast_manager & m = fml.get_manager();
     expr_ref_vector disjs(m);
     expr_ref_vector conjs(m);
     dl_decl_util util(m);
     bool_rewriter brw(m);
     table_fact fact;
     iterator it = begin();
     iterator iend = end();
     for(; it != iend; ++it) {
         const row_interface & r = *it;   
         r.get_fact(fact);
         conjs.reset();
         for (unsigned i = 0; i < fact.size(); ++i) {
             conjs.push_back(m.mk_eq(m.mk_var(i, sig[i]), util.mk_numeral(fact[i], sig[i])));
         }
         brw.mk_and(conjs.size(), conjs.c_ptr(), fml);
         disjs.push_back(fml);
     }
     brw.mk_or(disjs.size(), disjs.c_ptr(), fml);        
 }
Esempio n. 21
0
    void resolve_rule(replace_proof_converter* pc, rule& r1, rule& r2, unsigned idx, 
                      expr_ref_vector const& s1, expr_ref_vector const& s2, rule& res) {
        if (!pc) return;
        ast_manager& m = s1.get_manager();
        dl_decl_util util(m);
        expr_ref fml1(m), fml2(m), fml3(m);
        r1.to_formula(fml1);
        r2.to_formula(fml2);
        res.to_formula(fml3);
        vector<expr_ref_vector> substs;
        svector<std::pair<unsigned, unsigned> > positions;
        substs.push_back(s1);
        substs.push_back(s2);

        scoped_coarse_proof _sc(m);
        proof_ref pr(m);
        proof_ref_vector premises(m);
        premises.push_back(m.mk_asserted(fml1));
        premises.push_back(m.mk_asserted(fml2));
        positions.push_back(std::make_pair(idx+1, 0));

        TRACE("dl", 
              tout << premises[0]->get_id() << " " << mk_pp(premises[0].get(), m) << "\n";
              tout << premises[1]->get_id() << " " << mk_pp(premises[1].get(), m) << "\n";); 
Esempio n. 22
0
File: edf-wm.c Progetto: Aand1/ROSCH
static inline int cpu_low_util(void)
{
	int cpu, cpu_low;
	resch_task_t *p;
	unsigned long u[NR_RT_CPUS+1] = {[0 ... NR_RT_CPUS] = 0};

	p = global_highest_prio_task();
	while (p) {
		if (split_is_on_cpu(p, cpu)) {
			u[p->cpu_id] += util_split(p, cpu);
		}
		else if (task_is_on_cpu(p, cpu)) {
			u[p->cpu_id] += util(p);
		}
		p = global_next_prio_task(p);
	}
	cpu_low = 0;
	for (cpu = 1; cpu < NR_RT_CPUS; cpu++) {
		if (u[cpu] < u[cpu_low]) {
			cpu_low = cpu;
		}
	}
	return cpu_low;
}
Esempio n. 23
0
int cond::SchemaIOVUtilities::execute(){

  bool dropSchema= hasOptionValue("drop");
  bool createSchema= hasOptionValue("create");
  
  cond::DbSession session = openDbSession("connect", Auth::COND_ADMIN_ROLE );

  cond::IOVSchemaUtility util( session, std::cout );

  cond::DbScopedTransaction trans( session );
  if( dropSchema || createSchema ){
    trans.start(false);
    if( dropSchema ){
      util.dropIOVContainer();
    }
    if( createSchema ){
      util.createIOVContainer();
    }
    trans.commit();
    return 0;
  } 

  throw cond::Exception("Option create or drop not provided.");
}
Esempio n. 24
0
 bool util(TreeNode* left, TreeNode* right) {
     if(!left && !right) return true;
     if(!left || !right) return false;
     if(left->val != right->val) return false;
     return util(left->left, right->right)&&util(left->right, right->left);
 }
Esempio n. 25
0
  void DatabaseIO::initialize(const Ioss::Region * /*region*/) const
  {
    if (!initialized_) {
      assert(layout_ == nullptr);
      assert(legend_ == nullptr);

      DatabaseIO *new_this = const_cast<DatabaseIO *>(this);

      if (properties.exists("FIELD_SEPARATOR")) {
        new_this->separator_ = properties.get("FIELD_SEPARATOR").get_string();
      }

      if (properties.exists("FILE_FORMAT")) {
        std::string format = properties.get("FILE_FORMAT").get_string();
        if (Ioss::Utils::case_strcmp(format, "spyhis") == 0) {
          new_this->fileFormat = SPYHIS;
        }
      }

      bool append = open_create_behavior() == Ioss::DB_APPEND;

      // Try to open file...
      new_this->logStream = nullptr;
      if (util().parallel_rank() == 0) {
        new_this->logStream = open_stream(get_filename(), &(new_this->streamNeedsDelete), append);

        if (new_this->logStream == nullptr) {
          std::ostringstream errmsg;
          errmsg << "ERROR: Could not create heartbeat file '" << get_filename() << "'\n";
          IOSS_ERROR(errmsg);
        }
      }

      // Pull variables from the regions property data...
      if (properties.exists("TIME_STAMP_FORMAT")) {
        new_this->tsFormat = properties.get("TIME_STAMP_FORMAT").get_string();
      }

      if (properties.exists("SHOW_TIME_STAMP")) {
        bool show_time_stamp = properties.get("SHOW_TIME_STAMP").get_int() == 1;
        if (!show_time_stamp) {
          new_this->tsFormat = "";
        }
      }

      if (properties.exists("PRECISION")) {
        new_this->precision_ = properties.get("PRECISION").get_int();
      }

      if (properties.exists("FIELD_WIDTH")) {
        new_this->fieldWidth_ = properties.get("FIELD_WIDTH").get_int();
      }
      else {
        // +1.xxxxxxe+00 The x count is the precision the "+1.e+00" is the 7
        new_this->fieldWidth_ = precision_ + 7;
      }

      if (properties.exists("SHOW_LABELS")) {
        new_this->showLabels = (properties.get("SHOW_LABELS").get_int() == 1);
      }

      if (properties.exists("SHOW_LEGEND")) {
        new_this->showLegend =
            (properties.get("SHOW_LEGEND").get_int() == 1 && !new_this->appendOutput);
      }

      if (properties.exists("SHOW_TIME_FIELD")) {
        new_this->addTimeField = (properties.get("SHOW_TIME_FIELD").get_int() == 1);
      }

      if (fileFormat == SPYHIS) {
        new_this->addTimeField = true;
        new_this->showLegend   = true;
        new_this->showLabels   = false;
        new_this->tsFormat     = "";
      }

      if (showLegend) {
        new_this->legend_ = new Layout(false, precision_, separator_, fieldWidth_);
        if (!tsFormat.empty()) {
          new_this->legend_->add_literal("+");
          new_this->legend_->add_literal(time_stamp(tsFormat));
          new_this->legend_->add_literal(" ");
        }

        if (addTimeField) {
          if (fileFormat == SPYHIS) {
            new_this->legend_->add_legend("TIME");
          }
          else {
            new_this->legend_->add_legend("Time");
          }
        }
      }
      new_this->initialized_ = true;
    }
  }
//=============================================================================
//==  Main program                                                           ==
//=============================================================================
void sim(int argc, char *argv[])
{
  double   lambda;      // Mean arrival rate (cust/sec)
  double   mu;          // Mean service rate (cust/sec)
  double   offered_load;

  // Create the simulation
  create("sim");

  // Output usage
  if (argc != 2)
  {
    printf("Usage: 'offered_load' - offered_load between 0 and 1 \n");
    return;
  }
  offered_load = atof(argv[1]);
  assert((offered_load > 0.0) && (offered_load < 1.0));

  // CSIM initializations
  Server1 = facility("Server1");
  Server2 = facility("Server2");
  Server3 = facility("Server3");
  Server4 = facility("Server4");
  Server5 = facility("Server5");
  Resp_table = table("Response time table");

  // Parameter initializations
  mu = 1.0;
  lambda = offered_load * (double)5;

  // Output begin-of-simulation banner
  printf("*** BEGIN SIMULATION *** \n");

  // Initiate generate function and hold for SIM_TIME
  generate(lambda, mu);
  hold(SIM_TIME);

  // Output results
  printf("============================================================= \n");
  printf("==   *** CSIM 5 x M/M/1 queueing system simulation ***     == \n");
  printf("============================================================= \n");
  printf("= Lambda               = %6.3f cust/sec   \n", lambda);
  printf("= Mu (for each server) = %6.3f cust/sec   \n", mu);
  printf("============================================================= \n");
  printf("= Total CPU time     = %6.3f sec      \n", cputime());
  printf("= Total sim time     = %6.3f sec      \n", clock);
  printf("= Total completions  = %ld cust       \n",
    (completions(Server1) + completions(Server2) + completions(Server3) + completions(Server4) + completions(Server5)));
  printf("=------------------------------------------------------------ \n");
  printf("= >>> Simulation results                                    - \n");
  printf("=------------------------------------------------------------ \n");
  printf("= Utilization 1        = %6.3f %%       \n", 100.0 * util(Server1));
  printf("= Mean num in system 1 = %6.3f cust     \n", qlen(Server1));
  printf("= Mean response time 1 = %6.3f sec      \n", resp(Server1));
  printf("= Mean service time 1  = %6.3f sec      \n", serv(Server1));
  printf("= Mean throughput 1    = %6.3f cust/sec \n", tput(Server1));
  printf("=------------------------------------------------------------ \n");
  printf("= Utilization 2        = %6.3f %%       \n", 100.0 * util(Server2));
  printf("= Mean num in system 2 = %6.3f cust     \n", qlen(Server2));
  printf("= Mean response time 2 = %6.3f sec      \n", resp(Server2));
  printf("= Mean service time 2  = %6.3f sec      \n", serv(Server2));
  printf("= Mean throughput 2    = %6.3f cust/sec \n", tput(Server2));
  printf("=------------------------------------------------------------ \n");
  printf("= Utilization 3        = %6.3f %%       \n", 100.0 * util(Server3));
  printf("= Mean num in system 3 = %6.3f cust     \n", qlen(Server3));
  printf("= Mean response time 3 = %6.3f sec      \n", resp(Server3));
  printf("= Mean service time 3  = %6.3f sec      \n", serv(Server3));
  printf("= Mean throughput 3    = %6.3f cust/sec \n", tput(Server3));
  printf("=------------------------------------------------------------ \n");
  printf("= Utilization 4        = %6.3f %%       \n", 100.0 * util(Server4));
  printf("= Mean num in system 4 = %6.3f cust     \n", qlen(Server4));
  printf("= Mean response time 4 = %6.3f sec      \n", resp(Server4));
  printf("= Mean service time 4  = %6.3f sec      \n", serv(Server4));
  printf("= Mean throughput 4    = %6.3f cust/sec \n", tput(Server4));
  printf("=------------------------------------------------------------ \n");
  printf("= Utilization 5        = %6.3f %%       \n", 100.0 * util(Server5));
  printf("= Mean num in system 5 = %6.3f cust     \n", qlen(Server5));
  printf("= Mean response time 5 = %6.3f sec      \n", resp(Server5));
  printf("= Mean service time 5  = %6.3f sec      \n", serv(Server5));
  printf("= Mean throughput 5    = %6.3f cust/sec \n", tput(Server5));
  printf("=------------------------------------------------------------ \n");
  printf("& Table mean for response time = %6.3f sec   \n",
    table_mean(Resp_table));
  printf("============================================================= \n");

  // Output end-of-simulation banner
  printf("*** END SIMULATION *** \n");
  getchar();
}
Esempio n. 27
0
void DatabaseIO::initialize(const Ioss::Region *region) const
{
    if (!initialized_) {
        assert(layout_ == NULL);
        assert(legend_ == NULL);

        DatabaseIO *new_this = const_cast<DatabaseIO*>(this);

        if (properties.exists("FILE_FORMAT")) {
            std::string format = properties.get("FILE_FORMAT").get_string();
            if (Ioss::Utils::case_strcmp(format, "spyhis") == 0)
                new_this->fileFormat = SPYHIS;
        }

        bool append = open_create_behavior() == Ioss::DB_APPEND;

        if (util().parallel_rank() == 0) {
            new_this->logStream = open_stream(get_filename().c_str(),
                                              &(new_this->streamNeedsDelete),
                                              append);
        } else {
            // All processors except processor 0
            new_this->logStream = NULL;
        }

        // Pull variables from the regions property data...
        if (properties.exists("TIME_STAMP_FORMAT")) {
            new_this->tsFormat = properties.get("TIME_STAMP_FORMAT").get_string();
        }

        if (properties.exists("PRECISION")) {
            new_this->precision_ = properties.get("PRECISION").get_int();
        }

        if (properties.exists("SHOW_LABELS")) {
            new_this->showLabels = (properties.get("SHOW_LABELS").get_int() == 1);
        }

        if (properties.exists("SHOW_LEGEND")) {
            new_this->showLegend = (properties.get("SHOW_LEGEND").get_int() == 1 && !new_this->appendOutput);
        }

        if (fileFormat == SPYHIS) {
            new_this->showLegend = true;
            new_this->showLabels = false;
            new_this->tsFormat = "";
        }

        if (showLegend) {
            new_this->legend_ = new Layout(false, precision_);
            if (!tsFormat.empty()) {
                new_this->legend_->add_literal("+");
                new_this->legend_->add_literal(time_stamp(tsFormat));
                new_this->legend_->add_literal(" ");
            }
            if (!fileFormat == SPYHIS)
                new_this->legend_->add_literal("Legend: ");

            if (!tsFormat.empty()) {
                new_this->legend_->add_literal("WallTime, ");
            }

            if (fileFormat == SPYHIS)
                new_this->legend_->add_literal("Time, ");
        }
        new_this->initialized_ = true;
    }
}
Esempio n. 28
0
Q_DECL_EXPORT int main(int argc, char *argv[])
{
    QSettings *settings = new QSettings(QDir::homePath()+"/.config/thumbterm/settings.ini", QSettings::IniFormat);
    defaultSettings(settings);

    QCoreApplication::setApplicationName("Thumbterm");

    // fork the child process before creating QGuiApplication
    int socketM;
    int pid = forkpty(&socketM,NULL,NULL,NULL);
    if( pid==-1 ) {
        qFatal("forkpty failed");
        exit(1);
    } else if( pid==0 ) {
        setenv("TERM", settings->value("terminal/envVarTERM").toByteArray(), 1);

        QString execCmd;
        for(int i=0; i<argc-1; i++) {
            if( QString(argv[i]) == "-e" )
                execCmd = QString(argv[i+1]);
        }
        if(execCmd.isEmpty()) {
            execCmd = settings->value("gen/execCmd").toString();
        }
        if(execCmd.isEmpty()) {
            // Unset POSIXLY_CORRECT as having it set causes bash to start in POSIX mode (http://www.delorie.com/gnu/docs/bash/bashref_62.html#IDX214)
            // which causes it to not read the .bashrc on startup (http://lists.gnu.org/archive/html/bug-bash/2001-10/msg00117.html)
            unsetenv("POSIXLY_CORRECT");

            // execute the user's default shell
            passwd *pwdstruct = getpwuid(getuid());
            execCmd = QString(pwdstruct->pw_shell);
            execCmd.append(" --login");
        }

        if(settings)
            delete settings; // don't need 'em here

        QStringList execParts = execCmd.split(' ', QString::SkipEmptyParts);
        if(execParts.length()==0)
            exit(0);
        char *ptrs[execParts.length()+1];
        for(int i=0; i<execParts.length(); i++) {
            ptrs[i] = new char[execParts.at(i).toLatin1().length()+1];
            memcpy(ptrs[i], execParts.at(i).toLatin1().data(), execParts.at(i).toLatin1().length());
            ptrs[i][execParts.at(i).toLatin1().length()] = 0;
        }
        ptrs[execParts.length()] = 0;

        execvp(execParts.first().toLatin1(), ptrs);
        exit(0);
    }

    QGuiApplication app(argc, argv);
    QQuickWindow::setDefaultAlphaBuffer(true);

    QScreen* sc = app.primaryScreen();
    if(sc){
    sc->setOrientationUpdateMask(Qt::PrimaryOrientation
                                 | Qt::LandscapeOrientation
                                 | Qt::PortraitOrientation
                                 | Qt::InvertedLandscapeOrientation
                                 | Qt::InvertedPortraitOrientation);
    }

    qmlRegisterType<TextRender>("TextRender",1,0,"TextRender");
    MainWindow view;

    Terminal term;
    Util util(settings);
    term.setUtil(&util);
    QString startupErrorMsg;

    // copy the default config files to the config dir if they don't already exist
    copyFileFromResources(":/data/menu.xml", util.configPath()+"/menu.xml");
    copyFileFromResources(":/data/english.layout", util.configPath()+"/english.layout");
    copyFileFromResources(":/data/finnish.layout", util.configPath()+"/finnish.layout");
    copyFileFromResources(":/data/french.layout", util.configPath()+"/french.layout");
    copyFileFromResources(":/data/german.layout", util.configPath()+"/german.layout");
    copyFileFromResources(":/data/qwertz.layout", util.configPath()+"/qwertz.layout");

    KeyLoader keyLoader;
    keyLoader.setUtil(&util);
    bool ret = keyLoader.loadLayout( settings->value("ui/keyboardLayout").toString() );
    if(!ret) {
        // on failure, try to load the default one (english) directly from resources
        startupErrorMsg = "There was an error loading the keyboard layout.<br>\nUsing the default one instead.";
        settings->setValue("ui/keyboardLayout", "english");
        ret = keyLoader.loadLayout(":/data/english.layout");
        if(!ret)
            qFatal("failure loading keyboard layout");
    }

    QQmlContext *context = view.rootContext();
    context->setContextProperty( "term", &term );
    context->setContextProperty( "util", &util );
    context->setContextProperty( "keyLoader", &keyLoader );

    view.setSource(QUrl("qrc:/qml/Main.qml"));

    QObject *root = view.rootObject();
    if(!root)
        qFatal("no root object - qml error");

    QObject* win = root->findChild<QObject*>("window");

    if(!startupErrorMsg.isEmpty())
        QMetaObject::invokeMethod(win, "showErrorMessage", Qt::QueuedConnection, Q_ARG(QVariant, startupErrorMsg));

    TextRender *tr = root->findChild<TextRender*>("textrender");
    tr->setUtil(&util);
    tr->setTerminal(&term);
    term.setRenderer(tr);
    term.setWindow(&view);
    util.setWindow(&view);
    util.setTerm(&term);
    util.setRenderer(tr);

    QObject::connect(&term,SIGNAL(displayBufferChanged()),win,SLOT(displayBufferChanged()));
    QObject::connect(view.engine(),SIGNAL(quit()),&app,SLOT(quit()));

    QSize screenSize = QGuiApplication::primaryScreen()->size();
    if ((screenSize.width() < 1024 || screenSize.height() < 768 || app.arguments().contains("-fs"))
            && !app.arguments().contains("-nofs"))
    {
        view.showFullScreen();
    } else
        view.show();

    PtyIFace ptyiface(pid, socketM, &term,
                       settings->value("terminal/charset").toString());

    if( ptyiface.failed() )
        qFatal("pty failure");

    return app.exec();
}
Esempio n. 29
0
  void DatabaseIO::initialize(const Ioss::Region *region) const
  {
    if (!initialized_) {
      assert(layout_ == NULL);
      assert(legend_ == NULL);

      DatabaseIO *new_this = const_cast<DatabaseIO*>(this);

      if (properties.exists("FIELD_SEPARATOR")) {
	new_this->separator_ = properties.get("FIELD_SEPARATOR").get_string();
      }

      if (properties.exists("FILE_FORMAT")) {
	std::string format = properties.get("FILE_FORMAT").get_string();
	if (Ioss::Utils::case_strcmp(format, "spyhis") == 0)
	  new_this->fileFormat = SPYHIS;
      }

      bool append = open_create_behavior() == Ioss::DB_APPEND;

      if (util().parallel_rank() == 0) {

        new_this->logStream = open_stream(get_filename(),
            &(new_this->streamNeedsDelete),
            append);

        if (new_this->logStream == NULL) {
	  Ioss::FileInfo path = Ioss::FileInfo(get_filename());
	  Ioss::Utils::create_path(path.pathname());
	  new_this->logStream = open_stream(get_filename(),
              &(new_this->streamNeedsDelete),
              append);
        }
      } else {
	// All processors except processor 0
	new_this->logStream = NULL;
      }

      // Pull variables from the regions property data...
      if (properties.exists("TIME_STAMP_FORMAT")) {
	new_this->tsFormat = properties.get("TIME_STAMP_FORMAT").get_string();
      }

      if (properties.exists("SHOW_TIME_STAMP")) {
	bool show_time_stamp = properties.get("SHOW_TIME_STAMP").get_int() == 1;
	if (!show_time_stamp) {
	  new_this->tsFormat="";
	}
      }

      if (properties.exists("PRECISION")) {
	new_this->precision_ = properties.get("PRECISION").get_int();
      }

      if (properties.exists("FIELD_WIDTH")) {
	new_this->fieldWidth_ = properties.get("FIELD_WIDTH").get_int();
      } else {
	// +1.xxxxxxe+00 The x count is the precision the "+1.e+00" is the 7
	new_this->fieldWidth_ = precision_ + 7;
      }	

      if (properties.exists("SHOW_LABELS")) {
	new_this->showLabels = (properties.get("SHOW_LABELS").get_int() == 1);
      }

      if (properties.exists("SHOW_LEGEND")) {
	new_this->showLegend = (properties.get("SHOW_LEGEND").get_int() == 1 && !new_this->appendOutput);
      }

      if (properties.exists("SHOW_TIME_FIELD")) {
	new_this->addTimeField = (properties.get("SHOW_TIME_FIELD").get_int() == 1);
      }

      if (fileFormat == SPYHIS) {
	new_this->addTimeField = true;
	new_this->showLegend = true;
	new_this->showLabels = false;
	new_this->tsFormat = "";
      }
      
      if (showLegend) {
	new_this->legend_ = new Layout(false, precision_, separator_, fieldWidth_);
	if (!tsFormat.empty()) {
	  new_this->legend_->add_literal("+");
	  new_this->legend_->add_literal(time_stamp(tsFormat));
	  new_this->legend_->add_literal(" ");
	}

	if (addTimeField) {
	  new_this->legend_->add_legend("Time");
	}
      }
      new_this->initialized_ = true;
    }
  }
Esempio n. 30
0
void C ()
{
  util ();
  callutil10times ();
}