001package com.pi4j.system;
002
003/*
004 * #%L
005 * **********************************************************************
006 * ORGANIZATION  :  Pi4J
007 * PROJECT       :  Pi4J :: Java Library (Core)
008 * FILENAME      :  SystemInfoFactory.java
009 *
010 * This file is part of the Pi4J project. More information about
011 * this project can be found here:  http://www.pi4j.com/
012 * **********************************************************************
013 * %%
014 * Copyright (C) 2012 - 2016 Pi4J
015 * %%
016 * This program is free software: you can redistribute it and/or modify
017 * it under the terms of the GNU Lesser General Public License as
018 * published by the Free Software Foundation, either version 3 of the
019 * License, or (at your option) any later version.
020 *
021 * This program is distributed in the hope that it will be useful,
022 * but WITHOUT ANY WARRANTY; without even the implied warranty of
023 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
024 * GNU General Lesser Public License for more details.
025 *
026 * You should have received a copy of the GNU General Lesser Public
027 * License along with this program.  If not, see
028 * <http://www.gnu.org/licenses/lgpl-3.0.html>.
029 * #L%
030 */
031
032
033import com.pi4j.concurrent.DefaultExecutorServiceFactory;
034import com.pi4j.concurrent.ExecutorServiceFactory;
035import com.pi4j.io.gpio.GpioController;
036import com.pi4j.io.gpio.GpioProvider;
037import com.pi4j.io.gpio.impl.GpioControllerImpl;
038import com.pi4j.platform.PlatformManager;
039
040/**
041 * <p>This factory class provides a static method to create new 'GpioController' instances. </p>
042 *
043 * <p>
044 * Before using the Pi4J library, you need to ensure that the Java VM in configured with access to
045 * the following system libraries:
046 * <ul>
047 * <li>pi4j</li>
048 * <li>wiringPi</li>
049 * </ul>
050 *
051 * <blockquote> This library depends on the wiringPi native system library.</br> (developed by
052 * Gordon Henderson @ <a href="http://wiringpi.com/">http://wiringpi.com/</a>)
053 * </blockquote>
054 * </p>
055 *
056 * @see GpioController
057 * @see GpioProvider
058 *
059 * @see <a href="http://www.pi4j.com/">http://www.pi4j.com/</a>
060 * @author Robert Savage (<a
061 *         href="http://www.savagehomeautomation.com">http://www.savagehomeautomation.com</a>)
062 */
063@SuppressWarnings("unused")
064public class SystemInfoFactory {
065
066    // we only allow a single default provider to exists
067    private static SystemInfoProvider provider = null;
068
069    // private constructor
070    private SystemInfoFactory() {
071        // forbid object construction
072    }
073
074    /**
075     * <p>Return default instance of {@link SystemInfoProvider}.</p>
076     *
077     * @return Return a new SystemInfoProvider impl instance.
078     */
079    public static SystemInfoProvider getProvider() {
080        // if a provider has not been created, then create a new instance
081        if (provider == null) {
082            // create the provider based on the PlatformManager's selected platform
083            provider = PlatformManager.getPlatform().getSystemInfoProvider();
084        }
085
086        // return the provider instance
087        return provider;
088    }
089
090    /**
091     * Sets default {@link SystemInfoProvider}.
092     *
093     * @param provider default system info provider
094     */
095    public static void setProvider(SystemInfoProvider provider) {
096        // set the default provider instance
097        SystemInfoFactory.provider = provider;
098    }
099}