void CFileBrowser::formatFilesystem(void){
    QString filename;
    struct link_stat st;
    int err;
    int fmt;
    QTreeWidgetItem* item;
    CNotify notify;
    item = ui->tree->currentItem();
    filename = item->text(1);

    //check to see if this is a directory or a file
    err = link()->stat( item->text(1).toLocal8Bit().constData(),
                        &st);
    if ( err < 0 ){
        qDebug("Stat failed");
        notify.execLinkError(link_errno);
        return;
    }

    fmt = st.st_mode & LINK_S_IFMT;
    switch(fmt){
    case LINK_S_IFDIR:
        err = link()->format(filename.toLocal8Bit().constData());
        break;
    default:
        qDebug("Unknown file type");
        break;
    }
    if ( err ){
        notify.execLinkError(link_errno);
    }
    this->refresh();
    CNotify::updateStatus("Formatted " + filename);
}
void CFileBrowser::refresh(void){
    //Update the tree
    CNotify notify;

    if ( link()->get_is_connected() == false ){
        //Error::showNotConnected();
        return;
    }

    ui->tree->clear();

    topItem = new QTreeWidgetItem();
    if ( topItem == NULL ){
        notify.execError("Top Item is NULL");
        return;
    }

    if ( ui->gotoLine->text() == "" ){
        //Goto to "/" as the default directory
        ui->gotoLine->setText("/");
    }

    topItem->setText(0, ui->gotoLine->text() );
    topItem->setText(1, ui->gotoLine->text() );
    topItem->setText(2, "false" );
    ui->tree->addTopLevelItem(topItem);
    ui->tree->setCurrentItem(topItem, 0);

    loadDirectory(topItem);
}
int Monitor::signalProcess(int signo){
    int row;
    int pid;
    int err;
    QTableWidgetItem * item;
    CNotify notify;

    if ( link()->isConnected() == false ){
        notify.execNotConnected();
        return -1;
    }

    row = ui->table->currentRow();
    if ( row != 0 ){
        item = ui->table->item(row, PROCESS_ID_COL);
        if ( item == NULL ){
            return -1;
        }

        pid = item->text().replace(" (thread)", "").toInt();
        if( pid != 0 ){
            if ( (err = link()->kill_pid(pid, signo)) < 0 ){
                notify.execError(errorMessage());
            } else {
                ui->table->removeRow(row);
            }
        }
    }
    return 0;
}
Example #4
0
void * ThreadPool::work(void *p)
{
	ThreadPool* pool = (ThreadPool*)p;
	
	int fd = 0;
	while(1)
	{cout << "test\n";
		fd = 0;
		while(!fd)
		{
			cout << "pth_id" << pthread_self() << endl;
			fd = pool->m_socketList.pop();

		}
		//接收请求

		
		CSockApi cs(fd);
		CNotify notify;
		cs.receive_notify(notify);
		

		studentInfo stu;
		stu = *(studentInfo*)notify.get_data(&stu);
		
		LOG_DEBUG("sockid:%d",fd);
		LOG_ERROR("id:%d\nname:%s",stu.m_id,stu.m_name);
		//SQL sql;
		//sql.Connect();

		sleep(2);
		//sql.Insert(buf+16);
	}
	return pool;
}//线程函数
void CFileBrowser::runApp(void){
    struct link_stat st;
    int err;
    CNotify notify;
    QTreeWidgetItem* item;
    item = ui->tree->currentItem();
    if( item == 0 ){
        notify.execError("Invalid Selection");
        return;
    }

    err = link()->stat( item->text(1).toLocal8Bit().constData(),
                        &st);

    if ( err < 0 ){
        notify.execLinkError(link_errno);
        return;
    }

    if ( (st.st_mode & LINK_S_IFMT) != LINK_S_IFREG ){
        notify.execError("File is not executable");
        return;
    }

    if( st.st_mode & (LINK_S_IXGRP|LINK_S_IXOTH|LINK_S_IXUSR) ){
        //Execute a program on the target device
        emit runApplication( ui->tree->currentItem()->text(1) );
    } else {
        notify.execError("File is not executable");
    }
}
void CFileBrowser::on_downloadButton_clicked(){
    CNotify notify;
    if( topItem != 0 ){
        this->saveFileToDevice();
    } else {
        notify.execInfo("No Target Folder Selected");
    }
}
void CFileBrowser::on_uploadButton_clicked(){
    CNotify notify;
    if( topItem != 0 ){
        this->loadFileFromDevice();
    } else {
        notify.execInfo("No Source File Selected");
    }
}
void CFileBrowser::on_deleteButton_clicked(){
    CNotify notify;
    if( topItem != 0 ){
        this->deleteFile();
    } else {
        notify.execInfo("No File Selected");
    }
}
Example #9
0
int CSockApi::receive_notify(CNotify& pNotify)
{
	readN((char*)&pNotify,16);
	pNotify.n2h();
	pNotify.resize(pNotify.get_len());
	char *pdata = pNotify.get_data();
	return readN(pdata,pNotify.get_len());
	
}
void CFileBrowser::on_tree_itemActivated(QTreeWidgetItem* item, int column){
    CNotify notify;
    qDebug("item activated %s %s", item->text(0).toLocal8Bit().constData(), item->text(1).toLocal8Bit().constData());
    if ( column != 0 ){
        notify.execError("Invalid Column");
        return;
    }
    loadDirectory(item);
    item->setExpanded(true);
}
void CFileBrowser::saveFileToDeviceSelected(QStringList filenames){
    CNotify notify;

    if( copyFilesToDevice(link(), filenames, ui->tree->currentItem()->text(1)) == false ){
        notify.execLinkError(link_errno);
    } else {
        notify.updateStatus("File Saved");
        refresh();
    }
}
Example #12
0
void CaosIsp::operationComplete(QString msg, bool err){
  CNotify notify;
  if ( err == true ){
      notify.execError(msg);
    }  else if ( msg != "" ){
      if ( currentMessage != "" ){
          msg += ", " + currentMessage;
        }
      ui->statusBar->showMessage("      " + msg, 3000);
    }
}
void CApplicationInstaller::on_uninstallButton_clicked()
{
    CNotify notify;
    QString projectName = ui->installer->project();
    int pid;

    if( CNotify::notification() != 0 ){
        if( (pid = link()->get_is_executing(projectName.toStdString())) >= 0 ){
            connect(CNotify::notification(), SIGNAL(dismissed(int)), this, SLOT(uninstallPrompt(int)));
            notify.execPrompt("Kill " + ui->installer->project() + "?");
            return;
        }
    } else {
void CFileBrowser::on_formatButton_clicked()
{
    QString filename;
    QTreeWidgetItem* item;

    CNotify notify;
    if( topItem != 0 ){
        item = ui->tree->currentItem();
        filename = item->text(1);
        qDebug("format %s", filename.toLocal8Bit().constData());
        link()->format(filename.toStdString());
        this->refresh();
    } else {
        notify.execInfo("No Mount Selected to Format");
    }
}
Example #15
0
/*! \details This is the main window constructor.  It initializes the GUI as
 * as well as the USB Link driver.
 *
 *
 */
Caoslink::Caoslink(QWidget *parent) :
  QMainWindow(parent),
  ui(new Ui::Caoslink)
{
  CNotify notify;
  notify.updateStatus("");
  qDebug("CAOS Init");
  CLink * linkDevice;
  QCoreApplication::setOrganizationName("CoActionOS, Inc");
  QCoreApplication::setOrganizationDomain("coactionos.com");
  QCoreApplication::setApplicationName("CoActionOS Link");
  QCoreApplication::setApplicationVersion(COACTIONOS_LINK_VERSION);

  CFont::init();
  link_set_debug(1);

  ui->setupUi(this);
  linkDevice = ui->connectWidget->clink();
  ui->caosInterface->setLink(linkDevice);
  ui->progressBar->setVisible(false);

  //Connect link thread
  connect(linkDevice, SIGNAL(reconnectSignal(bool)), ui->connectWidget, SLOT(connectRequested(bool)));
  ui->connectWidget->setObjectName("connectWidget");
  ui->statusBar->setObjectName("statusBar");

  QFile file(":/data/CStyle.css");
  if(file.open(QFile::ReadOnly)) {
      QString StyleSheet = QLatin1String(file.readAll());
      file.close();
#ifdef Q_WS_WIN
      file.setFileName(":/data/CStyle-win32.css");
      if( file.open(QFile::ReadOnly)){
          StyleSheet += QLatin1String(file.readAll());
          file.close();
        }
#endif
      qApp->setStyleSheet(StyleSheet);
    }

  CNotify::setUpdateObjects(ui->statusBar, ui->progressBar);
  qDebug("CAOS Init Complete");

}
bool CFileBrowser::copyDirToDevice(CLink * d, QString srcDir, QString targetDir){
    QDir dir(srcDir);
    CNotify notify;
    QStringList files;
    bool ret;
    int i;
    files = dir.entryList(QDir::Files);
    for(i=0; i < files.size(); i++){
        ret = copyFileToDevice(d,
                             dir.path() + "/" + files.at(i),
                             targetDir
                             );
        if( ret < 0 ){
            return false;
        }
        notify.updateStatus("Copied " + files.at(i));
    }
    return true;
}
void CFileBrowser::loadFileFromDeviceSelected(QString filename){
    QString src, dest;
    QStringList path;
    int err;
    CNotify notify;

    src = ui->tree->currentItem()->text(1);
    path = src.split('/');

    if ( path.count() ){
        dest = filename + "/" + path[ path.count() -1 ];
        err = link()->copy(src.toStdString(), dest.toStdString(), 0, false, updateProgress);
        if ( err < 0 ){
            notify.execLinkError(link_errno);
        }
    } else {
        notify.execError("Invalid File");
    }

    CNotify::updateStatus("Uploaded to:  " + dest);

}
Example #18
0
bool Monitor::isRunningUser(void){
    sys_taskattr_t task;
    int id;
    int err;
    CNotify notify;


    if( fd < 0 ){
        if ( link()->isConnected() == true ){
            fd = link()->open("/dev/sys", LINK_O_RDWR);
        }
    }
    id = 0;
    do {
        if ( link()->isConnected() == false ){
            return -1;
        }

        task.is_enabled = 0;
        task.tid = id;
        err = link()->ioctl(fd, I_SYS_GETTASK, &task);
        if ( err < -2 ){
            notify.execError(errorMessage() );
            return -1;
        }

        if( task.is_enabled != 0 ){
            if( QString(task.name) != "sys" ){
                return true;
            }
        }

        id++;
    } while( err != -1 );

    return false;
}
Example #19
0
void Monitor::updateAll(){
    int id;
    int err;
    int row;
    int cpuRow;
    uint64_t totalTime;
    uint64_t taskTime;
    sys_taskattr_t task;
    CNotify notify;
    id = 0;

    if( link()->isConnected() == false ){
        return;
    }

    if( fd < 0 ){
        return;
    }

    do {
        if ( link()->isConnected() == false ){
            stopTimer();
            for(row = 0; row < ui->table->rowCount(); row++){
                ui->table->removeRow(row);
            }
            return;
        }

        task.is_enabled = 0;
        task.tid = id;
        err = link()->ioctl(fd, I_SYS_GETTASK, &task);
        if ( err < -2 ){
            stopTimer();
            for(row = 0; row < ui->table->rowCount(); row++){
                ui->table->removeRow(row);
            }
            notify.execError( errorMessage() );
            return;
        }

        //update the entries in the table
        updateRow(id, &task);
        id++;
    } while( err != -1 );


    cpuRow = ui->table->rowCount();
    totalTime = 0;
    for(row = 0; row < cpuRow; row++){
        totalTime += ui->table->item(row, DELTA_TASK_TIME_COL)->text().toLongLong();
    }


    for(row = 0; row < cpuRow; row++){
        taskTime = ui->table->item(row, DELTA_TASK_TIME_COL)->text().toLongLong();
        updateItem(row, CPU_COL, QString::number( taskTime * 100.0 / totalTime, 'f', 2 ));
    }

    ui->table->sortItems(sortColumn, sortOrder);


}
Example #20
0
int CSockApi::send_notify(CNotify& pNotify)
{
	return writeN(pNotify.get_send(),pNotify.get_size());
}
void CFileBrowser::loadDirectory(QTreeWidgetItem * treeItem){
    int dirp;
    int err;
    QString dName;
    QTreeWidgetItem * child;
    QString currentDirectory;
    struct link_dirent entry;
    CNotify notify;

    //First read the current directory or root if no directory has been selected
    currentDirectory = treeItem->text(1);
    qDebug("loadDirectory:%s", currentDirectory.toLocal8Bit().constData());

    if ( ( treeItem->text(0) == "." ) ||
         ( treeItem->text(0) == ".." ) ){
        //These are aliases to the current and parent directory and should not expanded
        return;
    }

    //Check to see if the directory has already been loaded
    if ( treeItem->text(2) == "false" ){

        //mark the directory as having already been loaded
        treeItem->setText(2, "true");
        qDebug("Opendir %s", currentDirectory.toLocal8Bit().constData());
        dirp = link()->opendir(currentDirectory.toLocal8Bit().constData());

        qDebug("Open dir:%s at 0x%X", currentDirectory.toLocal8Bit().constData(), dirp );

        if( dirp > 0 ){
            while( link()->readdir_r(dirp, &entry, NULL) == 0 ){

                dName = QString(entry.d_name);

                if ( dName != "" ){
                    if ( (dName != ".") &&
                         (dName != "..") ){

                        child = new QTreeWidgetItem();

                        child->setText(0, dName);
                        if ( currentDirectory == "/" ){
                            child->setText(1, currentDirectory + dName);
                        } else {
                            child->setText(1, currentDirectory + "/" + dName);
                        }

                        child->setText(2, "false"); //Mark the new directory as having not been loaded
                        if ( ui->showHiddenFilesCheckBox->checkState() == Qt::Checked ){
                            treeItem->addChild(child);
                        } else if ( !dName.startsWith(".") ){
                            treeItem->addChild(child);
                        }
                    }
                }
            }
            err = link()->closedir(dirp);
            if ( err < 0 ){
                notify.execLinkError(link_errno);
            }
        }

    } else {
        qDebug("Item %s already loaded", treeItem->text(2).toLocal8Bit().constData());
    }
}