23 Nisan 2021 Cuma

Unix Linux sistemlerinde Semapor kullanımı

 

#include <stdio.h>
#include <string.h>
#include<unistd.h>
#include<semaphore.h>
#include<pthread.h>
#include <stdlib.h>
void exit_sys(const char* msg);
void exit_sys_result(const char *msg,int result);

void *thread_proc1(void *param);
void *thread_proc2(void *param);

void do_something(const char *msg);

sem_t g_sem;


int main(void)
{
    printf("Hello World!\n");

    int result;
    pthread_t tid1,tid2;
    srand(time(NULL));


    if(sem_init(&g_sem,0,1)==-1)
    {
        exit_sys("sem_init");
    }

    if((result=pthread_create(&tid1,NULL,thread_proc1,NULL))!=0)
    {
          exit_sys_result("thread create1",result);
    }

    if((result=pthread_create(&tid2,NULL,thread_proc2,NULL))!=0)
    {
           exit_sys_result("thread create2",result);
    }

    pthread_join(tid1,NULL);
    pthread_join(tid2,NULL);
    sem_destroy(&g_sem);


    return 0;
}


void *thread_proc1(void *param)
{
    int i;
    for(i=0;i<10;i++)
    {
        do_something(" thread-1 ");
    }
    return NULL;
}

void *thread_proc2(void *param)
{
    int i;
    for(i=0;i<10;i++)
    {
        do_something(" thread-2 ");
    }
    return NULL;
}

void do_something(const char *str)
{
    sem_wait(&g_sem);
    printf("-----------------------\n");
    printf("%s: Step-1\n",str);
    usleep(rand()%300000);
    printf("%s: Step-2\n",str);
    usleep(rand()%300000);
    printf("%s: Step-3\n",str);
    usleep(rand()%300000);
    printf("%s: Step-4\n",str);
    usleep(rand()%300000);
    printf("%s: Step-5\n",str);
    usleep(rand()%300000);
    sem_post(&g_sem);

}
void exit_sys(const char *msg)
{
    perror(msg);
    exit(EXIT_FAILURE);
}
void exit_sys_result(const char *msg, int result)
{
    fprintf(stderr, "%s: %s\n", msg, strerror(result));
    exit(EXIT_FAILURE);
}






















Share:

4 Şubat 2021 Perşembe

QTableview datalarını CSV dosyasına aktarma ( Convert QTableview to CSVFile

 





void DeviceSettingsClass::tableToCSV()

{

QString filters("CSV files (*.csv);;All files (*.*)");

QString defaultFilter("CSV files (*.csv)");

QString fileName = QFileDialog::getSaveFileName(0, "Save file", QCoreApplication::applicationDirPath(),

filters, &defaultFilter);

QFile file(fileName);


QAbstractItemModel* model = main_class_for_devset->recTableDevice->model();

if (file.open(QFile::WriteOnly | QFile::Truncate)) {

QTextStream data(&file);

QStringList strList;

for (int i = 0; i < model->columnCount(); i++) 

{

if (model->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString().length() > 0)

strList.append("\"" + model->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString() + "\"");

else

strList.append("");

}

data << strList.join(";") << "\n";

for (int i = 0; i < model->rowCount(); i++)

{

strList.clear();

for (int j = 0; j < model->columnCount(); j++)

{


if (model->data(model->index(i, j)).toString().length() > 0)

strList.append("\"" + model->data(model->index(i, j)).toString() + "\"");

else

strList.append("");

}

data << strList.join(";") + "\n";

}

file.close();

}

}


Share:

27 Ocak 2021 Çarşamba

Run Function with Qt::Concurrent in QT (Bir fonksiyonu başka threadde çalıştırma)

 //Qt::concurrent ile bir fonksiyonu baska bir threadde calıstırma 

örn:  Bir  void RecordWidget::ProcessGPS_rec2(NvrHandler* hnd, unsigned char* data, unsigned int dataSize)     fonksiyonunu başka threadde kosturalım 

      QFuture<void> future = QtConcurrent::run(this, &RecordWidget::ProcessGPS_rec2, hnd, data,dataSize);      şeklinde başka thread tasırız .

Share:

13 Ocak 2021 Çarşamba

EnterCriticalSection Deadlock Fix

 Add your project 


// PROTECT FOR ENTERCRITIALSECTION DEADLOCK

extern "C" const IMAGE_LOAD_CONFIG_DIRECTORY _load_config_used =

{

sizeof(IMAGE_LOAD_CONFIG_DIRECTORY),

0,

0,

0,

0,

0,

2000, // CriticalSectionDefaultTimeout msec

0,

0,

0,

0,

0,

0,

0,

0,

0,

0

};

Share:

28 Aralık 2020 Pazartesi

23 Aralık 2020 Çarşamba

Create mosaic video with VLC

 new   channel1 broadcast enabled                                                       

setup channel1 input file:///video-sub1.nvrbuf

setup channel1 output #duplicate{dst=mosaic-bridge{id=1,width=384,height=216}}  

  

new   channel2 broadcast enabled                                                       

setup channel2 input file:///video-sub2.nvrbuf

setup channel2 output #duplicate{dst=mosaic-bridge{id=2,width=384,height=216}}    

          

new mosaic broadcast enabled

setup mosaic input file:///a.png

setup mosaic output #transcode{sfilter=mosaic,vcodec=mp4v,VB=20000,acodec=none,fps=25,scale=1}:display




control mosaic play

control channel1 play

control channel2 play


Share: