<commit_before>/*
   (c) Copyright 2000  convergence integrated media GmbH.
   All rights reserved.

   Written by <NAME> <<EMAIL>> and
              <NAME> <<EMAIL>>.

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with this library; if not, write to the
   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.
*/


#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <dlfcn.h>

#include <string.h>
#include <malloc.h>

#include <pthread.h>

#include "directfb.h"

#include "core.h"
#include "coredefs.h"
#include "coretypes.h"

#include "reactor.h"
#include "layers.h"
#include "input.h"

#include "misc/mem.h"
#include "misc/util.h"

InputDevice *inputdevices = NULL;


static CoreModuleLoadResult input_driver_handle_func( void *handle,
                                                      char *name,
                                                      void *ctx );


/** public **/

DFBResult input_init_devices()
{
     char *driver_dir = MODULEDIR"/inputdrivers";

     core_load_modules( driver_dir, input_driver_handle_func, NULL );

     return DFB_OK;
}

void input_deinit()
{
     InputDevice *d = inputdevices;

     while (d) {
          InputDevice *next = d->next;

          pthread_cancel( d->event_thread );
          pthread_join( d->event_thread, NULL );

          reactor_free( d->reactor );

          d->info.driver->DeInit( d );

          DFBFREE( d->info.driver );
          DFBFREE( d );

          d = next;
     }

     inputdevices = NULL;
}

DFBResult input_suspend()
{
     InputDevice *d = inputdevices;

     DEBUGMSG( "DirectFB/core/input: suspending...\n" );

     while (d) {
          pthread_cancel( d->event_thread );
          pthread_join( d->event_thread, NULL );
          //d->info.driver->DeInit( d );
          
          d = d->next;
     }

     DEBUGMSG( "DirectFB/core/input: ...suspended\n" );
     
     return DFB_OK;
}

DFBResult input_resume()
{
     InputDevice *d = inputdevices;

     DEBUGMSG( "DirectFB/core/input: resuming...\n" );
     
     while (d) {
          //d->info.driver->Init( d );
          pthread_create( &d->event_thread, NULL,
                           d->EventThread, d );
          
          d = d->next;
     }

     DEBUGMSG( "DirectFB/core/input: ...resumed\n" );
     
     return DFB_OK;
}


/** internal **/

static CoreModuleLoadResult input_driver_handle_func( void *handle,
                                                      char *name,
                                                      void *ctx )
{
     int n, nr_devices;
     InputDriver *driver = DFBMALLOC( sizeof(InputDriver) );
     
     driver->Probe  = dlsym( handle, "driver_probe" );
     if (!driver->Probe) {
          DLERRORMSG( "DirectFB/core/input: "
                      "Could not dlsym `driver_probe' from `%s'!\n", name );
          DFBFREE( driver );
          return MODULE_REJECTED;
     }

     driver->Init   = dlsym( handle, "driver_init" );<commit_msg>Reverted last patch that disabled deinit/init during suspend/resume.<commit_after>/*
   (c) Copyright 2000  convergence integrated media GmbH.
   All rights reserved.

   Written by <NAME> <<EMAIL>> and
              <NAME> <<EMAIL>>.

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with this library; if not, write to the
   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.
*/


#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <dlfcn.h>

#include <string.h>
#include <malloc.h>

#include <pthread.h>

#include "directfb.h"

#include "core.h"
#include "coredefs.h"
#include "coretypes.h"

#include "reactor.h"
#include "layers.h"
#include "input.h"

#include "misc/mem.h"
#include "misc/util.h"

InputDevice *inputdevices = NULL;


static CoreModuleLoadResult input_driver_handle_func( void *handle,
                                                      char *name,
                                                      void *ctx );


/** public **/

DFBResult input_init_devices()
{
     char *driver_dir = MODULEDIR"/inputdrivers";

     core_load_modules( driver_dir, input_driver_handle_func, NULL );

     return DFB_OK;
}

void input_deinit()
{
     InputDevice *d = inputdevices;

     while (d) {
          InputDevice *next = d->next;

          pthread_cancel( d->event_thread );
          pthread_join( d->event_thread, NULL );

          reactor_free( d->reactor );

          d->info.driver->DeInit( d );

          DFBFREE( d->info.driver );
          DFBFREE( d );

          d = next;
     }

     inputdevices = NULL;
}

DFBResult input_suspend()
{
     InputDevice *d = inputdevices;

     DEBUGMSG( "DirectFB/core/input: suspending...\n" );

     while (d) {
          pthread_cancel( d->event_thread );
          pthread_join( d->event_thread, NULL );
          d->info.driver->DeInit( d );
          
          d = d->next;
     }

     DEBUGMSG( "DirectFB/core/input: ...suspended\n" );
     
     return DFB_OK;
}

DFBResult input_resume()
{
     InputDevice *d = inputdevices;

     DEBUGMSG( "DirectFB/core/input: resuming...\n" );
     
     while (d) {
          d->info.driver->Init( d );
          pthread_create( &d->event_thread, NULL,
                           d->EventThread, d );
          
          d = d->next;
     }

     DEBUGMSG( "DirectFB/core/input: ...resumed\n" );
     
     return DFB_OK;
}


/** internal **/

static CoreModuleLoadResult input_driver_handle_func( void *handle,
                                                      char *name,
                                                      void *ctx )
{
     int n, nr_devices;
     InputDriver *driver = DFBMALLOC( sizeof(InputDriver) );
     
     driver->Probe  = dlsym( handle, "driver_probe" );
     if (!driver->Probe) {
          DLERRORMSG( "DirectFB/core/input: "
                      "Could not dlsym `driver_probe' from `%s'!\n", name );
          DFBFREE( driver );
          return MODULE_REJECTED;
     }

     driver->Init   = dlsym( handle, "driver_init" );
{'fraction_non_alphanumeric': 0.10908836297437334, 'fraction_numerical': 0.005321383559725529, 'mean_word_length': 2.0326963906581743, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7082974', 'n_tokens_mistral': 2197, 'n_tokens_neox': 2111, 'n_words': 617}