<commit_before>package com.cibuddy.ibuddy.impl;

import com.cibuddy.hid.HIDServiceConstants;
import com.codeminders.hidapi.HIDDeviceInfo;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.util.tracker.ServiceTracker;

/**
 *
 * @author mirkojahn
 */
public class Activator implements BundleActivator{

    //private static String filterString = "(&(" + Constants.OBJECTCLASS + "="+HIDDeviceInfo.class.getName()+")("+HIDServiceConstants.VENDOR_ID+"=4400)("+HIDServiceConstants.USAGE+">=1))";
    // on linux, we do not know which of the two exposed hid devices is actually the correct one. We have to try both at runtime unfortunately.
    private static String filterString = "(&(" + Constants.OBJECTCLASS + "="+HIDDeviceInfo.class.getName()+")("+HIDServiceConstants.VENDOR_ID+"=4400))";
    
    private static BundleContext ctx;
    private static ServiceTracker lightsTracker = null;
    private HIDDeviceInfoServiceTrackerCustomizer customizer;
    
    
    @Override
    public void start(BundleContext bc) throws Exception {
        ctx = bc;
        customizer = new HIDDeviceInfoServiceTrackerCustomizer();
        // some important services we might need
        lightsTracker = new ServiceTracker(bc, bc.createFilter(filterString), customizer);
        lightsTracker.open();

    }

    @Override
    public void stop(BundleContext bc) throws Exception {
        if(customizer != null){
            customizer.close();
            customizer = null;
        }
        
        if(lightsTracker != null){
            lightsTracker.close();
            lightsTracker = null;
        }
    }
    
    public static BundleContext getBundleContext(){
        return ctx;
    }
    
}<commit_msg>Improved logging and handling of none linux devices (linux is bad for identifying the correct HID device for a working i-Buddy - currently 2 instead of 1)<commit_after>package com.cibuddy.ibuddy.impl;

import com.cibuddy.hid.HIDServiceConstants;
import com.codeminders.hidapi.HIDDeviceInfo;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.util.tracker.ServiceTracker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author mirkojahn
 */
public class Activator implements BundleActivator {

    private static final Logger LOG = LoggerFactory.getLogger(Activator.class);
    
    private static String filterString = "(&(" + Constants.OBJECTCLASS + "=" + HIDDeviceInfo.class.getName() + ")(" + HIDServiceConstants.VENDOR_ID + "=4400)(" + HIDServiceConstants.USAGE + ">=1))";
    // on linux, we do not know which of the two exposed hid devices is actually the correct one. We have to try both at runtime unfortunately.
    private static String filterString_linux = "(&(" + Constants.OBJECTCLASS + "=" + HIDDeviceInfo.class.getName() + ")(" + HIDServiceConstants.VENDOR_ID + "=4400))";
    private static BundleContext ctx;
    private static ServiceTracker lightsTracker = null;
    private HIDDeviceInfoServiceTrackerCustomizer customizer;

    @Override
    public void start(BundleContext bc) throws Exception {
        ctx = bc;
        customizer = new HIDDeviceInfoServiceTrackerCustomizer();
        
        // in case of unix, we can't make enough assumptions. Be less restrictive
        if(isUnix()) {
            // ultimately this will result in 2 hid devices, where only one will work
            filterString = filterString_linux;
            LOG.info("Using relaxed filter string for linux. This will result "
                    + "in 2 i-Buddy devices, although only one does in fact work! "
                    + "Test which one before applying your configuration!");
        }
        lightsTracker = new ServiceTracker(bc, bc.createFilter(filterString), customizer);
        lightsTracker.open();

    }

    @Override
    public void stop(BundleContext bc) throws Exception {
        if (customizer != null) {
            customizer.close();
            customizer = null;
        }

        if (lightsTracker != null) {
            lightsTracker.close();
            lightsTracker = null;
        }
    }

    public final static BundleContext getBundleContext() {
        return ctx;
    }

    public final static boolean isUnix() {
        String os = System.getProperty("os.name").toLowerCase();
        // linux or unix
        return (os.indexOf("nix") >= 0 || os.indexOf("nux") >= 0);

    }
}
{'fraction_non_alphanumeric': 0.09931431099314311, 'fraction_numerical': 0.0057509400575094, 'mean_word_length': 3.0628930817610063, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2143302', 'n_tokens_mistral': 1257, 'n_tokens_neox': 1227, 'n_words': 345}