<commit_before>/**************************************************************************
 * Copyright 2014 Marcelo Sardelich <MSardelich@gmail.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 ***************************************************************************/
#include <iostream>
#include <string>
#include <exception>
#include <stdexcept>
#include <vector>
#include <map>
#include <cassert>

#include "CJay.hpp"

#define MAX_TOLERANCE 1.0e-4

using namespace VM;

jint CJ::JNI_VERSION = JNI_VERSION_1_8; // Depends on installed JDK!

int main (int argc, char* argv[]) {
    // Create JVM
    std::vector<std::string> paramVM{"-ea", "-Xdebug"};
    VM::createVM(paramVM);
    //VM::createVM();

    CJ CJ;

    // Set class
    try {
        CJ.setClass("example/Example");
    } catch(std::exception& e) {
        std::cout << e.what() << std::endl;
        VM::destroyVM();
        return EXIT_FAILURE;
    }

    // Print signatures
    CJ.printSignatures();

    // Call constructor
    try {
        CJ.Constructor("<init>"); // contructor has no parameters
    } catch(std::exception& e) {
        std::cout << e.what() << std::endl;
        VM::destroyVM();
        return EXIT_FAILURE;
    }

    // Instantiate caster
    Converter cnv;

    // Assertions
    try {

        jboolean Z = CJ.call<jboolean>( "parseBoolean", (jboolean) false );
        assert (Z == false);

        jbyte B = CJ.call<jbyte>( "parseByte", (jbyte) 123 );
        assert ( (int) B == 123); // convert from signed char to int

        jchar C = CJ.call<jchar>( "parseChar", (jchar) 'a' ); // single 16-bit unicode
        assert (C == 'a');

        jshort S = CJ.call<jshort>( "parseShort", (jshort) -12 );
        assert (S == -12); // coversion to int avoids lost precision

        jint I = CJ.call<jint>("parseInt", (jint) 123 );
        assert (I == 123);

        jlong J = CJ.call<jlong>( "parseLong", (jlong) 123456 );
        assert (J == 123456);

        jfloat F = CJ.call<float>( "parseFloat", (jfloat) 123.456 );
        assert ( abs(F - (float) 123.456) <= MAX_TOLERANCE );

        jdouble D = CJ.call<jdouble>( "parseDouble", (jdouble) 123.456789 );
        assert ( abs(D - (double) 123.456789) <= MAX_TOLERANCE );

        jobject L = CJ.call<jobject>( "parseString", cnv.j_cast<jstring>("foo") );
        std::string str = cnv.c_cast<std::string>(L); // From java.lang.String To string
        assert ( str == std::string("foo") );

        L = CJ.call<jobject>( "parseArrayListByte", (jbyte) 123, (jbyte) -123 );
        std::vector<jbyte> vb = cnv.c_cast_vector<jbyte>(L, 2); // From java.lang.ArrayList<byte> To vector<jbyte> (or vector<signed char>)
        assert ( (int) vb[0] == 123 ); assert( (int) vb[1] == -123 ); // convert signed char to int

        L = CJ.call<jobject>( "parseArrayListInteger", (jint) 123, (jint) 456 );
        std::vector<jint> vi = cnv.c_cast_vector<jint>(L, 2); // From ArrayList<Integer> To vector<jint> (or vector<long>)
        //std::cout << vi[0] << " " << vi[1] << std::endl;
        assert ( vi[0] == 123 ); assert( vi[1] == 456 );

        L = CJ.call<jobject>( "parseArrayListLong", (jlong) 123456, (jlong) 123789 );
        std::vector<jlong> vl = cnv.c_cast_vector<jlong>(L, 2); // From ArrayList<Long> To vector<jlong> (or vector<__int64>)
        assert ( vl[0] == 123456 ); assert( vl[1] == 123789 );

        L = CJ.call<jobject>( "parseArrayListShort", (jshort) -12, (jshort) +13 );
        std::vector<jshort> vs = cnv.c_cast_vector<jshort>(L, 2); // From ArrayList<Short> To vector<jshort> (or vector<short>)
        assert ( vs[0] == -12 ); assert( vs[1] == +13 );

        L = CJ.call<jobject>( "parseArrayListFloat", (jfloat) -123.123, (jfloat) 123.145 );
        std::vector<jfloat> vf = cnv.c_cast_vector<jfloat>(L, 2); // From ArrayList<Float> To vector<jfloat> (or vector<float>)
        assert ( abs(vf[0] - (float) -123.123) <= MAX_TOLERANCE ); assert ( abs(vf[1] - (float) 123.145) <= MAX_TOLERANCE );

        L = CJ.call<jobject>( "parseArrayListDouble", (jdouble) 123.1234, (jdouble) -123.4567 );
        std::vector<jdouble> vd = cnv.c_cast_vector<jdouble>(L, 2); // From ArrayList<Double> To vector<jdouble> (or vector<double>)
        assert ( abs(vd[0] - (double) 123.1234) <= MAX_TOLERANCE ); assert ( abs(vd[1] - (double) -123.4567) <= MAX_TOLERANCE );

        L = CJ.call<jobject>( "parseArrayListString", cnv.j_cast<jstring>("foo") , cnv.j_cast<jstring>("bar"));
        std::vector<std::string> v_str = cnv.c_cast_vector<std::string>(L, 2); // From ArrayList<String> To vector<string>
        assert ( v_str[0] == "foo" ); assert( v_str[1] == "bar" );

        L = CJ.call<jobject>( "parseSimpleMap", cnv.j_cast<jstring>("foo") , cnv.j_cast<jstring>("bar"), cnv.j_cast<jstring>("foo.bar"));
        std::map<std::string, std::string> m_str_str = cnv.c_cast_map<std::string, std::string>(L); // From java.util.Map<String, String> To std::map<string, string>
        assert ( m_str_str["arg 1"] == "foo" ); assert ( m_str_str["arg 2"] == "bar" ); assert ( m_str_str["arg 3"] == "foo.bar" );

    } catch(std::exception& e) {
        std::cout << e.what() << std::endl;
        VM::destroyVM();
        return EXIT_FAILURE;
    }

    // Destroy VM
    VM::destroyVM();

    return EXIT_SUCCESS;
}
<commit_msg>add jarray test<commit_after>/**************************************************************************
 * Copyright 2014 Marcelo Sardelich <MSardelich@gmail.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 ***************************************************************************/
#include <iostream>
#include <string>
#include <exception>
#include <stdexcept>
#include <vector>
#include <map>
#include <cassert>

#include "CJay.hpp"
#include "example/Example.hpp"

#define MAX_TOLERANCE 1.0e-4

jint VM::CJ::JNI_VERSION = DEFAULT_JNI_VERSION; // Depends on installed JDK!

using namespace VM;

int main (int argc, char* argv[]) {
    // Create JVM
    std::vector<std::string> paramVM{"-ea", "-Xdebug"};
    VM::createVM(paramVM);
    //VM::createVM();

    CJ CJ;

    // Set class
    try {
        CJ.setClass("example/Example");
    } catch(std::exception& e) {
        std::cout << e.what() << std::endl;
        VM::destroyVM();
        return EXIT_FAILURE;
    }

    // Print signatures
    CJ.printSignatures();

    // Call constructor
    try {
        CJ.Constructor("<init>"); // contructor has no parameters
    } catch(std::exception& e) {
        std::cout << e.what() << std::endl;
        VM::destroyVM();
        return EXIT_FAILURE;
    }

    // Instantiate caster
    Converter cnv;

    // test
    try {
        cjay::example::Example example;
        jboolean test = example.parseBoolean((jboolean) false);
        assert (test == false);
    } catch(std::exception& e) {
        std::cout << e.what() << std::endl;
        VM::destroyVM();
        return EXIT_FAILURE;
    }

    // Assertions
    try {

        std::vector<jboolean> in {true, false};
        jbooleanArray Za = CJ.call<jbooleanArray>( "parseArrayBoolean", cnv.j_cast<jbooleanArray>(in) );
        std::vector<jboolean> vB = cnv.c_cast_array<jboolean>(Za);
        assert (vB[0] == true); assert (vB[1] == false);

        jboolean Z = CJ.call<jboolean>( "parseBoolean", (jboolean) false );
        assert (Z == false);

        jbyte B = CJ.call<jbyte>( "parseByte", (jbyte) 123 );
        assert ( (int) B == 123); // convert from signed char to int

        jchar C = CJ.call<jchar>( "parseChar", (jchar) 'a' ); // single 16-bit unicode
        assert (C == 'a');

        jshort S = CJ.call<jshort>( "parseShort", (jshort) -12 );
        assert (S == -12); // coversion to int avoids lost precision

        jint I = CJ.call<jint>("parseInt", (jint) 123 );
        assert (I == 123);

        jlong J = CJ.call<jlong>( "parseLong", (jlong) 123456 );
        assert (J == 123456);

        jfloat F = CJ.call<float>( "parseFloat", (jfloat) 123.456 );
        assert ( abs(F - (float) 123.456) <= MAX_TOLERANCE );

        jdouble D = CJ.call<jdouble>( "parseDouble", (jdouble) 123.456789 );
        assert ( abs(D - (double) 123.456789) <= MAX_TOLERANCE );

        jobject L = CJ.call<jobject>( "parseString", cnv.j_cast<jstring>("foo") );
        std::string str = cnv.c_cast<std::string>(L); // From java.lang.String To string
        assert ( str == std::string("foo") );

        L = CJ.call<jobject>( "parseArrayListByte", (jbyte) 123, (jbyte) -123 );
        std::vector<jbyte> vb = cnv.c_cast_vector<jbyte>(L, 2); // From java.lang.ArrayList<byte> To vector<jbyte> (or vector<signed char>)
        assert ( (int) vb[0] == 123 ); assert( (int) vb[1] == -123 ); // convert signed char to int

        L = CJ.call<jobject>( "parseArrayListInteger", (jint) 123, (jint) 456 );
        std::vector<jint> vi = cnv.c_cast_vector<jint>(L, 2); // From ArrayList<Integer> To vector<jint> (or vector<long>)
        //std::cout << vi[0] << " " << vi[1] << std::endl;
        assert ( vi[0] == 123 ); assert( vi[1] == 456 );

        L = CJ.call<jobject>( "parseArrayListLong", (jlong) 123456, (jlong) 123789 );
        std::vector<jlong> vl = cnv.c_cast_vector<jlong>(L, 2); // From ArrayList<Long> To vector<jlong> (or vector<__int64>)
        assert ( vl[0] == 123456 ); assert( vl[1] == 123789 );

        L = CJ.call<jobject>( "parseArrayListShort", (jshort) -12, (jshort) +13 );
        std::vector<jshort> vs = cnv.c_cast_vector<jshort>(L, 2); // From ArrayList<Short> To vector<jshort> (or vector<short>)
        assert ( vs[0] == -12 ); assert( vs[1] == +13 );

        L = CJ.call<jobject>( "parseArrayListFloat", (jfloat) -123.123, (jfloat) 123.145 );
        std::vector<jfloat> vf = cnv.c_cast_vector<jfloat>(L, 2); // From ArrayList<Float> To vector<jfloat> (or vector<float>)
        assert ( abs(vf[0] - (float) -123.123) <= MAX_TOLERANCE ); assert ( abs(vf[1] - (float) 123.145) <= MAX_TOLERANCE );

        L = CJ.call<jobject>( "parseArrayListDouble", (jdouble) 123.1234, (jdouble) -123.4567 );
        std::vector<jdouble> vd = cnv.c_cast_vector<jdouble>(L, 2); // From ArrayList<Double> To vector<jdouble> (or vector<double>)
        assert ( abs(vd[0] - (double) 123.1234) <= MAX_TOLERANCE ); assert ( abs(vd[1] - (double) -123.4567) <= MAX_TOLERANCE );

        L = CJ.call<jobject>( "parseArrayListString", cnv.j_cast<jstring>("foo") , cnv.j_cast<jstring>("bar"));
        std::vector<std::string> v_str = cnv.c_cast_vector<std::string>(L, 2); // From ArrayList<String> To vector<string>
        assert ( v_str[0] == "foo" ); assert( v_str[1] == "bar" );

        L = CJ.call<jobject>( "parseSimpleMap", cnv.j_cast<jstring>("foo") , cnv.j_cast<jstring>("bar"), cnv.j_cast<jstring>("foo.bar"));
        std::map<std::string, std::string> m_str_str = cnv.c_cast_map<std::string, std::string>(L); // From java.util.Map<String, String> To std::map<string, string>
        assert ( m_str_str["arg 1"] == "foo" ); assert ( m_str_str["arg 2"] == "bar" ); assert ( m_str_str["arg 3"] == "foo.bar" );

    } catch(std::exception& e) {
        std::cout << e.what() << std::endl;
        VM::destroyVM();
        return EXIT_FAILURE;
    }

    // Destroy VM
    VM::destroyVM();

    return EXIT_SUCCESS;
}
<|endoftext|>


<commit_before>#ifndef TCL_CONTROLLER_HPP
#define TCL_CONTROLLER_HPP

#include <string>

#include "CLDeviceInformation.hpp"
#include "CLInformation.hpp"

#include "CLSource.hpp"
#include "CLSourceArray.hpp"

#include "CLWorkGroupSettings.hpp"
#include "CLExecuteProperty.hpp"
#include "CLExecute.hpp"

#include "CLBuffer.hpp"
#include "CLReadBuffer.hpp"
#include "CLReadWriteBuffer.hpp"
#include "CLWriteBuffer.hpp"

namespace tcl
{
	/**
	* @brief foCX̎
	*/
	enum class DeviceType
	{
		GPU,
		CPU
	};

	/**
	* @brief TinyCL𐧌䂷邽߂̃Rg[
	*/
	class CLController
	{
		CLSource* source;
		const CLDeviceInformation* device;
		CLWorkGroupSettings* setting;
		CLExecute* exec;

		std::vector<CLBuffer*> argWrite;
		std::vector<CLBuffer*> argRead;

	private:
		void InitSetting(const cl_uint dimension, const std::vector<size_t>& offset, const std::vector<size_t>& workerRange, const std::vector<size_t>& splitSize)
		{
			if (setting != nullptr)
				delete setting;	// xĂяo΍

			setting = new CLWorkGroupSettings(dimension, offset, workerRange, splitSize);
			setting->Optimize(*device);
		}

	public:
		/**
		* @brief TinyCL𐧌䂷邽߂̃Rg[
		* \param [in] sourcePath \[XR[h̃pX
		* \param [in] kernelFunction Gg[|CgɂȂ֐
		* \param [in] deviceType foCX̎
		* \param [in] sourceType \[XR[h̎
		*/
		CLController(const std::string& sourcePath, const std::string& kernelFunction, const DeviceType& deviceType = DeviceType::GPU, const SourceType& sourceType = SourceType::Text)
		{
			switch (deviceType)
			{
			case DeviceType::GPU:
				device = &information.GetGPU();
				break;

			case DeviceType::CPU:
				device = &information.GetCPU();
				break;
			}

			if (device == nullptr)
				throw CLDeviceNotFoundException("Ώۂ̃foCX܂ł");

			source = new CLSource(sourcePath, kernelFunction, sourceType);
			exec = new CLExecute(*source, *device);
		}

		/**
		* @brief [J[̐ݒׂw肷
		* @param [in] offset [J[̏ʒu
		* @param [in] workerRange [J[̐
		* @param [in] splitSize [J[̋؂
		*/
		CLController& Setting(const std::vector<size_t>& offset, const std::vector<size_t>& workerRange, const std::vector<size_t>& splitSize)
		{
			if (offset.size() != workerRange.size() || offset.size() != splitSize.size())
				throw CLException("[J[̎eňvĂ܂");
			InitSetting(offset.size(), offset, workerRange, splitSize);
			return *this;
		}

		/**
		* @brief ɉoffset, workerRange𑵂Ă
		* @param [in] offset [J[̏ʒu
		* @param [in] workerRange [J[̐
		*/
		CLController& Setting(const std::vector<size_t>& offset, const std::vector<size_t>& workerRange)
		{
			if (offset.size() != workerRange.size())
				throw CLException("[J[̎eňvĂ܂");
			InitSetting(offset.size(), offset, workerRange, workerRange);
			return *this;
		}

		/**
		* @brief Ƃ肠C[J[𑽎œĂ݂ƂɎg
		* @param [in] workerRange [J[̐
		*/
		CLController& Setting(const std::vector<size_t>& workerRange)
		{
			std::vector<size_t> offset(workerRange.size(), 0);
			std::vector<size_t> splitSize(workerRange.size());
			for (int i = 0; i < workerRange.size(); ++i)
				splitSize[i] = workerRange[i];

			InitSetting(offset.size(), offset, workerRange, workerRange);
			return *this;
		}

		/**
		* @brief 1ƂāCoffsetX^[gCworkerRange̐[J[𓮂
		* @param [in] offset [J[̏ʒu
		* @param [in] workerRange [J[̐
		*/
		CLController& Setting(const size_t& offset, const size_t& workerRange)
		{
			InitSetting(1, { offset }, { workerRange } , { workerRange });
			return *this;
		}

		/**
		* @brief 1ƂāCwokerRange̐[J[𓮂
		* @param [in] workerRange [J[̐
		*/
		CLController& Setting(const size_t& workerRange)
		{
			InitSetting(1, { 0 }, { workerRange }, { workerRange });
			return *this;
		}

		template <typename T>
		CLController& Run(CLReadBuffer<T>& buffer)
		{

		}

		template <typename T>
		CLController& Run(CLWriteBuffer<T>& buffer)
		{

		}

		template <typename T>
		CLController& Run(CLReadWriteBuffer<T>& buffer)
		{

		}

		/**
		* J[ls
		*/
		template <typename BUFFER, typename... Args>
		CLController& Run(BUFFER& buffer, Args&... args)
		{
			Run(args);
			return *this;
		}

		/**
		* J[lR[h̎s҂
		*/
		CLController& Wait()
		{
			exec->Wait();
			return *this;
		}

		virtual ~CLController()
		{
			delete exec;
			delete setting;
			delete source;
		}
	};
}

#endif<commit_msg>ちょこちょこ追加する<commit_after>#ifndef TCL_CONTROLLER_HPP
#define TCL_CONTROLLER_HPP

#include <string>

#include "CLDeviceInformation.hpp"
#include "CLInformation.hpp"

#include "CLSource.hpp"
#include "CLSourceArray.hpp"

#include "CLWorkGroupSettings.hpp"
#include "CLExecuteProperty.hpp"
#include "CLExecute.hpp"

#include "CLBuffer.hpp"
#include "CLReadBuffer.hpp"
#include "CLReadWriteBuffer.hpp"
#include "CLWriteBuffer.hpp"

namespace tcl
{
	/**
	* @brief foCX̎
	*/
	enum class DeviceType
	{
		GPU,
		CPU
	};

	/**
	* @brief TinyCL𐧌䂷邽߂̃Rg[
	*/
	class CLController
	{
		CLSource* source;
		const CLDeviceInformation* device;
		CLWorkGroupSettings* setting;
		CLExecute* exec;

		std::vector<CLBuffer*> argWrite;
		std::vector<CLBuffer*> argRead;

	private:
		void InitSetting(const cl_uint dimension, const std::vector<size_t>& offset, const std::vector<size_t>& workerRange, const std::vector<size_t>& splitSize)
		{
			if (setting != nullptr)
				delete setting;	// xĂяo΍

			setting = new CLWorkGroupSettings(dimension, offset, workerRange, splitSize);
			setting->Optimize(*device);
		}

		template <typename T>
		CLController& SetAndRun(T& buffer)
		{
			exec->SetArg(buffer);
			exec->Run(*setting);
			return *this;
		}

	public:
		/**
		* @brief TinyCL𐧌䂷邽߂̃Rg[
		* \param [in] sourcePath \[XR[h̃pX
		* \param [in] kernelFunction Gg[|CgɂȂ֐
		* \param [in] deviceType foCX̎
		* \param [in] sourceType \[XR[h̎
		*/
		CLController(const std::string& sourcePath, const std::string& kernelFunction, const DeviceType& deviceType = DeviceType::GPU, const SourceType& sourceType = SourceType::Text)
		{
			switch (deviceType)
			{
			case DeviceType::GPU:
				device = &information.GetGPU();
				break;

			case DeviceType::CPU:
				device = &information.GetCPU();
				break;
			}

			if (device == nullptr)
				throw CLDeviceNotFoundException("Ώۂ̃foCX܂ł");

			source = new CLSource(sourcePath, kernelFunction, sourceType);
			exec = new CLExecute(*source, *device);
		}

		/**
		* @brief [J[̐ݒׂw肷
		* @param [in] offset [J[̏ʒu
		* @param [in] workerRange [J[̐
		* @param [in] splitSize [J[̋؂
		*/
		CLController& Setting(const std::vector<size_t>& offset, const std::vector<size_t>& workerRange, const std::vector<size_t>& splitSize)
		{
			if (offset.size() != workerRange.size() || offset.size() != splitSize.size())
				throw CLException("[J[̎eňvĂ܂");
			InitSetting(offset.size(), offset, workerRange, splitSize);
			return *this;
		}

		/**
		* @brief ɉoffset, workerRange𑵂Ă
		* @param [in] offset [J[̏ʒu
		* @param [in] workerRange [J[̐
		*/
		CLController& Setting(const std::vector<size_t>& offset, const std::vector<size_t>& workerRange)
		{
			if (offset.size() != workerRange.size())
				throw CLException("[J[̎eňvĂ܂");
			InitSetting(offset.size(), offset, workerRange, workerRange);
			return *this;
		}

		/**
		* @brief Ƃ肠C[J[𑽎œĂ݂ƂɎg
		* @param [in] workerRange [J[̐
		*/
		CLController& Setting(const std::vector<size_t>& workerRange)
		{
			std::vector<size_t> offset(workerRange.size(), 0);
			std::vector<size_t> splitSize(workerRange.size());
			for (int i = 0; i < workerRange.size(); ++i)
				splitSize[i] = workerRange[i];

			InitSetting(offset.size(), offset, workerRange, workerRange);
			return *this;
		}

		/**
		* @brief 1ƂāCoffsetX^[gCworkerRange̐[J[𓮂
		* @param [in] offset [J[̏ʒu
		* @param [in] workerRange [J[̐
		*/
		CLController& Setting(const size_t& offset, const size_t& workerRange)
		{
			InitSetting(1, { offset }, { workerRange } , { workerRange });
			return *this;
		}

		/**
		* @brief 1ƂāCwokerRange̐[J[𓮂
		* @param [in] workerRange [J[̐
		*/
		CLController& Setting(const size_t& workerRange)
		{
			InitSetting(1, { 0 }, { workerRange }, { workerRange });
			return *this;
		}

		template <typename T>
		CLController& Run(CLReadBuffer<T>& buffer)
		{
			argRead.push_back(&buffer);
			return SetAndRun(buffer);
		}

		template <typename T>
		CLController& Run(CLWriteBuffer<T>& buffer)
		{
			argWrite.push_back(&buffer);
			return SetAndRun(buffer);
		}

		template <typename T>
		CLController& Run(CLReadWriteBuffer<T>& buffer)
		{
			argRead.push_back(buffer);
			argWrite.push_back(buffer);
			return SetAndRun(buffer);
		}

		/**
		* J[ls
		*/
		template <typename BUFFER, typename... Args>
		CLController& Run(BUFFER& buffer, Args&... args)
		{
			Run(args);
			return *this;
		}

		/**
		* J[lR[h̎s҂
		*/
		CLController& Wait()
		{
			exec->Wait();
			argRead.clear();
			argWrite.clear();
			return *this;
		}

		virtual ~CLController()
		{
			delete exec;
			delete setting;
			delete source;
		}
	};
}

#endif<|endoftext|>


<commit_before>#include "Arduino.h"
#include "AddressableLEDStrip.h"

// Create the LED strip object with the clock pin, serial data pin and the number of LEDs in the strip.
AddressableLEDStrip::AddressableLEDStrip(int clk_pin, int sdi_pin, int num_leds)
{

  allow_out_of_bounds = false;

  strip_len = num_leds;

  // Create color arrays
  red_values = (int *) malloc(num_leds * sizeof(int));
  green_values = (int *) malloc(num_leds * sizeof(int));
  blue_values = (int *) malloc(num_leds * sizeof(int));

  // Set the arrays or return
  if(red_values) memset(red_values, 0, num_leds);
  else return;
  if(green_values) memset(green_values, 0, num_leds);
  else return;
  if(blue_values) memset(blue_values, 0, num_leds);
  else return;

  // Setup pins
  clk = clk_pin;
  sdi = sdi_pin;
  pinMode(sdi, OUTPUT);
  pinMode(clk, OUTPUT);
}

// Set the RGB value on a single LED
// This does not write anything to the strip.
void AddressableLEDStrip::set_led(uint16_t index, int red, int green, int blue)
{
  // Make sure index is within range
  if (index < strip_len) {

    // Update the value to be within the 0 - 255 boundary
    if (allow_out_of_bounds == false) {
      if (red < 0) red = 0;
      else if (red > 255) red = 255;

      if (green < 0) green = 0;
      else if (green > 255) green = 255;

      if (blue < 0) blue = 0;
      else if (blue > 255) blue = 255;
    }

    // Set values
    red_values[index] = red;
    green_values[index] = green;
    blue_values[index] = blue;
  }
}

// Sets all the LEDs to OFF
// This does not write them to the strip.
void AddressableLEDStrip::clear_all()
{
  set_all_leds(0, 0, 0);
}

// Clear the color values for an LED at this index
void AddressableLEDStrip::clear_led(int index)
{
	set_led(index, 0, 0, 0);
}

// Set the red color (0 - 255) for an LED at this index
void AddressableLEDStrip::set_red(int index, int color)
{
	set_led(index, color, get_green(index), get_blue(index));
}

// Set the green color (0 - 255) for an LED at this index
void AddressableLEDStrip::set_green(int index, int color)
{
	set_led(index, get_red(index), color, get_blue(index));
}

// Set the blue color (0 - 255) for an LED at this index
void AddressableLEDStrip::set_blue(int index, int color)
{
	set_led(index, get_red(index), get_green(index), index);
}

// Set all the LEDs to the same RGB value.
// This does not write them to the strip.
void AddressableLEDStrip::set_all_leds(int red, int green, int blue)
{
  for(int i = 0 ; i < strip_len ; i++) {
    set_led(i, red, green , blue);
  }
}

// Push the RGB values to the LED strip.
void AddressableLEDStrip::send()
{
    //Each LED requires 24 bits of data
  //MSB: R7, R6, R5..., G7, G6..., B7, B6... B0
  //Once the 24 bits have been delivered, the IC immediately relays these bits to its neighbor
  //Pulling the clock low for 500us or more causes the IC to post the data.

  for(int i = 0 ; i < strip_len ; i++) {
		_send_color_bits(get_red(i));
		_send_color_bits(get_green(i));
		_send_color_bits(get_blue(i));
  }

  //Pull clock low to put strip into reset/post mode
  digitalWrite(clk, LOW);
  delayMicroseconds(500); //Wait for 500us to go into reset
}

// Send the individual bits from this value to the LED strip.
void AddressableLEDStrip::_send_color_bits(int value)
{
  // Value must be between 0 - 255
  if (value < 0) value = 0;
  else if (value > 255) value = 255;

  // Pull 8 bits from the value
  //for(int bit_place = 7; bit_place >= 0; bit_place--) {
  for(int bit_place = 7; bit_place >= 0; bit_place--) {
     //int bit_mask = pow(2, bit_place); // 128, 64, 32, 16, 8, 4, 2, 1
     int bit_mask = 1 << bit_place;  // 128, 64, 32, 16, 8, 4, 2, 1

    // Pull clock low to set the value
    digitalWrite(clk, LOW);

    // Write value
    if(value & bit_mask)
      digitalWrite(sdi, HIGH);
    else
      digitalWrite(sdi, LOW);

    // Latch the new value in
    digitalWrite(clk, HIGH);
  }
}

// Get the number of LED that are in this strip (or at least what you set the length to be).
int AddressableLEDStrip::length()
{
  return strip_len;
}

// Get the red value at an LED index
int AddressableLEDStrip::get_red(int index)
{
  if (index < strip_len) {
    return red_values[index];
  }
  return 0;
}

// Get the green value at an LED index
int AddressableLEDStrip::get_green(int index)
{
  if (index < strip_len) {
    return green_values[index];
  }
  return 0;
}

// Get the blue value at an LED index
int AddressableLEDStrip::get_blue(int index)
{
  if (index < strip_len) {
    return blue_values[index];
  }
  return 0;
}<commit_msg>Fix set_blue() which was setting the color to the index. Whoops<commit_after>#include "Arduino.h"
#include "AddressableLEDStrip.h"

// Create the LED strip object with the clock pin, serial data pin and the number of LEDs in the strip.
AddressableLEDStrip::AddressableLEDStrip(int clk_pin, int sdi_pin, int num_leds)
{

  allow_out_of_bounds = false;

  strip_len = num_leds;

  // Create color arrays
  red_values = (int *) malloc(num_leds * sizeof(int));
  green_values = (int *) malloc(num_leds * sizeof(int));
  blue_values = (int *) malloc(num_leds * sizeof(int));

  // Set the arrays or return
  if(red_values) memset(red_values, 0, num_leds);
  else return;
  if(green_values) memset(green_values, 0, num_leds);
  else return;
  if(blue_values) memset(blue_values, 0, num_leds);
  else return;

  // Setup pins
  clk = clk_pin;
  sdi = sdi_pin;
  pinMode(sdi, OUTPUT);
  pinMode(clk, OUTPUT);
}

// Set the RGB value on a single LED
// This does not write anything to the strip.
void AddressableLEDStrip::set_led(uint16_t index, int red, int green, int blue)
{
  // Make sure index is within range
  if (index < strip_len) {

    // Update the value to be within the 0 - 255 boundary
    if (allow_out_of_bounds == false) {
      if (red < 0) red = 0;
      else if (red > 255) red = 255;

      if (green < 0) green = 0;
      else if (green > 255) green = 255;

      if (blue < 0) blue = 0;
      else if (blue > 255) blue = 255;
    }

    // Set values
    red_values[index] = red;
    green_values[index] = green;
    blue_values[index] = blue;
  }
}

// Sets all the LEDs to OFF
// This does not write them to the strip.
void AddressableLEDStrip::clear_all()
{
  set_all_leds(0, 0, 0);
}

// Clear the color values for an LED at this index
void AddressableLEDStrip::clear_led(int index)
{
	set_led(index, 0, 0, 0);
}

// Set the red color (0 - 255) for an LED at this index
void AddressableLEDStrip::set_red(int index, int color)
{
	set_led(index, color, get_green(index), get_blue(index));
}

// Set the green color (0 - 255) for an LED at this index
void AddressableLEDStrip::set_green(int index, int color)
{
	set_led(index, get_red(index), color, get_blue(index));
}

// Set the blue color (0 - 255) for an LED at this index
void AddressableLEDStrip::set_blue(int index, int color)
{
	set_led(index, get_red(index), get_green(index), color);
}

// Set all the LEDs to the same RGB value.
// This does not write them to the strip.
void AddressableLEDStrip::set_all_leds(int red, int green, int blue)
{
  for(int i = 0 ; i < strip_len ; i++) {
    set_led(i, red, green , blue);
  }
}

// Push the RGB values to the LED strip.
void AddressableLEDStrip::send()
{
    //Each LED requires 24 bits of data
  //MSB: R7, R6, R5..., G7, G6..., B7, B6... B0
  //Once the 24 bits have been delivered, the IC immediately relays these bits to its neighbor
  //Pulling the clock low for 500us or more causes the IC to post the data.

  for(int i = 0 ; i < strip_len ; i++) {
		_send_color_bits(get_red(i));
		_send_color_bits(get_green(i));
		_send_color_bits(get_blue(i));
  }

  //Pull clock low to put strip into reset/post mode
  digitalWrite(clk, LOW);
  delayMicroseconds(500); //Wait for 500us to go into reset
}

// Send the individual bits from this value to the LED strip.
void AddressableLEDStrip::_send_color_bits(int value)
{
  // Value must be between 0 - 255
  if (value < 0) value = 0;
  else if (value > 255) value = 255;

  // Pull 8 bits from the value
  //for(int bit_place = 7; bit_place >= 0; bit_place--) {
  for(int bit_place = 7; bit_place >= 0; bit_place--) {
     //int bit_mask = pow(2, bit_place); // 128, 64, 32, 16, 8, 4, 2, 1
     int bit_mask = 1 << bit_place;  // 128, 64, 32, 16, 8, 4, 2, 1

    // Pull clock low to set the value
    digitalWrite(clk, LOW);

    // Write value
    if(value & bit_mask)
      digitalWrite(sdi, HIGH);
    else
      digitalWrite(sdi, LOW);

    // Latch the new value in
    digitalWrite(clk, HIGH);
  }
}

// Get the number of LED that are in this strip (or at least what you set the length to be).
int AddressableLEDStrip::length()
{
  return strip_len;
}

// Get the red value at an LED index
int AddressableLEDStrip::get_red(int index)
{
  if (index < strip_len) {
    return red_values[index];
  }
  return 0;
}

// Get the green value at an LED index
int AddressableLEDStrip::get_green(int index)
{
  if (index < strip_len) {
    return green_values[index];
  }
  return 0;
}

// Get the blue value at an LED index
int AddressableLEDStrip::get_blue(int index)
{
  if (index < strip_len) {
    return blue_values[index];
  }
  return 0;
}<|endoftext|>


<commit_before>/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p9/procedures/hwp/memory/p9_mss_eff_config.C $ */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2015,2019                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */

///
/// @file p9_mss_eff_config.C
/// @brief Command and Control for the memory subsystem - populate attributes
///
// *HWP HWP Owner: Andre Marin <aamarin@us.ibm.com>
// *HWP HWP Backup: Brian Silver <bsilver@us.ibm.com>
// *HWP Team: Memory
// *HWP Level: 2
// *HWP Consumed by: FSP:HB

#include <p9_mss_eff_config.H>

// std
#include <map>

// fapi2
#include <fapi2.H>

// mss lib
#include <lib/spd/common/spd_decoder.H>
#include <lib/spd/spd_factory.H>
#include <lib/utils/pos.H>
#include <lib/utils/checker.H>
#include <lib/utils/find.H>
#include <lib/shared/mss_kind.H>
#include <lib/utils/find.H>
#include <lib/dimm/eff_dimm.H>
#include <lib/eff_config/plug_rules.H>
///
/// @brief Configure the attributes for each controller
/// @param[in] i_target the controller (e.g., MCS)
/// @param[in] i_decode_spd_only options to set VPD and SPD attrs only
/// @return FAPI2_RC_SUCCESS iff ok
///
fapi2::ReturnCode p9_mss_eff_config( const fapi2::Target<fapi2::TARGET_TYPE_MCS>& i_target,
                                     const bool i_decode_spd_only )
{
    fapi2::ReturnCode l_rc;
    std::map<uint32_t, std::shared_ptr<mss::spd::decoder> > l_factory_caches;
    // Caches
    FAPI_TRY( mss::spd::populate_decoder_caches(i_target, l_factory_caches) );

    // We need to decode the VPD. We don't do this in the ctor as we need
    // the rank information and for that we need the SPD caches (which we get when we populate the cache.)
    // However, we need to do the VPD decode before the others so that they might
    // be able to use VPD information to make decisions about setting up eff attributes.
    if( !i_decode_spd_only )
    {
        // Always set VPD attributes unless we enable the SPD_ONLY flag
        // Enables skipping VPD decoder when a valid VPD template isn't available
        FAPI_TRY( mss::eff_dimm::decode_vpd(i_target),
                  "Unable to decode VPD for %s", mss::c_str(i_target) );
    }

    for( const auto& l_dimm : mss::find_targets<fapi2::TARGET_TYPE_DIMM>(i_target) )
    {
        std::shared_ptr<mss::eff_dimm> l_eff_dimm;

        const auto l_dimm_pos = mss::pos(l_dimm);

        // TODO RTC:152390 Create function to do map checking on cached values
        // Find decoder factory for this dimm position
        auto l_it = l_factory_caches.find(l_dimm_pos);

        FAPI_TRY( mss::check::spd::invalid_cache(l_dimm,
                  l_it != l_factory_caches.end(),
                  l_dimm_pos),
                  "Failed to get valid cache (main decoder)");

        FAPI_TRY( mss::eff_dimm::eff_dimm_factory( l_dimm, l_it->second, l_eff_dimm));

        FAPI_TRY( l_eff_dimm->dram_mfg_id() );
        FAPI_TRY( l_eff_dimm->dram_width() );
        FAPI_TRY( l_eff_dimm->dram_density() );
        FAPI_TRY( l_eff_dimm->ranks_per_dimm() );
        FAPI_TRY( l_eff_dimm->primary_stack_type() );
        FAPI_TRY( l_eff_dimm->dimm_size() );
        FAPI_TRY( l_eff_dimm->hybrid_memory_type() );
        FAPI_TRY( l_eff_dimm->temp_refresh_mode() );
        FAPI_TRY( l_eff_dimm->dram_trefi() );
        FAPI_TRY( l_eff_dimm->dram_trfc() );
        FAPI_TRY( l_eff_dimm->dram_trfc_dlr() );
        FAPI_TRY( l_eff_dimm->rcd_mirror_mode() );
        FAPI_TRY( l_eff_dimm->dram_bank_bits() );
        FAPI_TRY( l_eff_dimm->dram_row_bits() );
        FAPI_TRY( l_eff_dimm->dram_dqs_time() );
        FAPI_TRY( l_eff_dimm->dram_tccd_l() );
        FAPI_TRY( l_eff_dimm->dimm_rc00() );
        FAPI_TRY( l_eff_dimm->dimm_rc01() );
        FAPI_TRY( l_eff_dimm->dimm_rc02() );
        FAPI_TRY( l_eff_dimm->dimm_rc03() );
        FAPI_TRY( l_eff_dimm->dimm_rc04() );
        FAPI_TRY( l_eff_dimm->dimm_rc05() );
        FAPI_TRY( l_eff_dimm->dimm_rc06_07() );
        FAPI_TRY( l_eff_dimm->dimm_rc08() );
        FAPI_TRY( l_eff_dimm->dimm_rc09() );
        FAPI_TRY( l_eff_dimm->dimm_rc10() );
        FAPI_TRY( l_eff_dimm->dimm_rc11() );
        FAPI_TRY( l_eff_dimm->dimm_rc12() );
        FAPI_TRY( l_eff_dimm->dimm_rc13() );
        FAPI_TRY( l_eff_dimm->dimm_rc14() );
        FAPI_TRY( l_eff_dimm->dimm_rc15() );
        FAPI_TRY( l_eff_dimm->dimm_rc1x() );
        FAPI_TRY( l_eff_dimm->dimm_rc2x() );
        FAPI_TRY( l_eff_dimm->dimm_rc3x() );
        FAPI_TRY( l_eff_dimm->dimm_rc4x() );
        FAPI_TRY( l_eff_dimm->dimm_rc5x() );
        FAPI_TRY( l_eff_dimm->dimm_rc6x() );
        FAPI_TRY( l_eff_dimm->dimm_rc7x() );
        FAPI_TRY( l_eff_dimm->dimm_rc8x() );
        FAPI_TRY( l_eff_dimm->dimm_rc9x() );
        FAPI_TRY( l_eff_dimm->dimm_rcax() );
        FAPI_TRY( l_eff_dimm->dimm_rcbx() );
        FAPI_TRY( l_eff_dimm->dram_twr() );
        FAPI_TRY( l_eff_dimm->read_burst_type() );
        FAPI_TRY( l_eff_dimm->dram_tm() );
        FAPI_TRY( l_eff_dimm->dram_cwl() );
        FAPI_TRY( l_eff_dimm->dram_lpasr() );
        FAPI_TRY( l_eff_dimm->dll_enable() );
        FAPI_TRY( l_eff_dimm->dll_reset() );
        FAPI_TRY( l_eff_dimm->write_level_enable() );
        FAPI_TRY( l_eff_dimm->output_buffer() );
        FAPI_TRY( l_eff_dimm->vref_dq_train_value() );
        FAPI_TRY( l_eff_dimm->vref_dq_train_range() );
        FAPI_TRY( l_eff_dimm->vref_dq_train_enable() );
        FAPI_TRY( l_eff_dimm->ca_parity_latency() );
        FAPI_TRY( l_eff_dimm->ca_parity_error_status() );
        FAPI_TRY( l_eff_dimm->ca_parity() );
        FAPI_TRY( l_eff_dimm->crc_error_clear() );
        FAPI_TRY( l_eff_dimm->odt_input_buffer() );
        FAPI_TRY( l_eff_dimm->post_package_repair() );
        FAPI_TRY( l_eff_dimm->read_preamble_train() );
        FAPI_TRY( l_eff_dimm->read_preamble() );
        FAPI_TRY( l_eff_dimm->write_preamble() );
        FAPI_TRY( l_eff_dimm->self_refresh_abort() );
        FAPI_TRY( l_eff_dimm->cs_to_cmd_addr_latency() );
        FAPI_TRY( l_eff_dimm->internal_vref_monitor() );
        FAPI_TRY( l_eff_dimm->max_powerdown_mode() );
        FAPI_TRY( l_eff_dimm->mpr_read_format() );
        FAPI_TRY( l_eff_dimm->temp_readout() );
        FAPI_TRY( l_eff_dimm->crc_wr_latency() );
        FAPI_TRY( l_eff_dimm->per_dram_addressability() );
        FAPI_TRY( l_eff_dimm->geardown_mode() );
        FAPI_TRY( l_eff_dimm->mpr_page() );
        FAPI_TRY( l_eff_dimm->mpr_mode() );
        FAPI_TRY( l_eff_dimm->write_crc() );
        FAPI_TRY( l_eff_dimm->zqcal_interval() );
        FAPI_TRY( l_eff_dimm->memcal_interval() );
        FAPI_TRY( l_eff_dimm->dram_trp() );
        FAPI_TRY( l_eff_dimm->dram_trcd() );
        FAPI_TRY( l_eff_dimm->dram_trc() );
        FAPI_TRY( l_eff_dimm->dram_twtr_l() );
        FAPI_TRY( l_eff_dimm->dram_twtr_s() );
        FAPI_TRY( l_eff_dimm->dram_trrd_s() );
        FAPI_TRY( l_eff_dimm->dram_trrd_l() );
        FAPI_TRY( l_eff_dimm->dram_trrd_dlr() );
        FAPI_TRY( l_eff_dimm->dram_tfaw() );
        FAPI_TRY( l_eff_dimm->dram_tfaw_dlr() );
        FAPI_TRY( l_eff_dimm->dram_tras() );
        FAPI_TRY( l_eff_dimm->dram_trtp() );
        FAPI_TRY( l_eff_dimm->read_dbi() );
        FAPI_TRY( l_eff_dimm->write_dbi() );
        FAPI_TRY( l_eff_dimm->additive_latency() );
        FAPI_TRY( l_eff_dimm->data_mask() );
        FAPI_TRY( l_eff_dimm->dimm_bc00());
        FAPI_TRY( l_eff_dimm->dimm_bc01());
        FAPI_TRY( l_eff_dimm->dimm_bc02());
        FAPI_TRY( l_eff_dimm->dimm_bc03());
        FAPI_TRY( l_eff_dimm->dimm_bc04());
        FAPI_TRY( l_eff_dimm->dimm_bc05());
        FAPI_TRY( l_eff_dimm->dimm_bc07());
        FAPI_TRY( l_eff_dimm->dimm_bc08());
        FAPI_TRY( l_eff_dimm->dimm_bc09());
        FAPI_TRY( l_eff_dimm->dimm_bc0a());
        FAPI_TRY( l_eff_dimm->dimm_bc0b());
        FAPI_TRY( l_eff_dimm->dimm_bc0c());
        FAPI_TRY( l_eff_dimm->dimm_bc0d());
        FAPI_TRY( l_eff_dimm->dimm_bc0e());
        FAPI_TRY( l_eff_dimm->dimm_bc0f());
        FAPI_TRY( l_eff_dimm->dram_rtt_nom () );
        FAPI_TRY( l_eff_dimm->dram_rtt_wr  () );
        FAPI_TRY( l_eff_dimm->dram_rtt_park() );
    }// dimm

    // TODO RTC:160060 Clean up hard coded values at bottom of eff_config
    // Don't set these attributes if we only want to set VPD attributes
    // This will be cleaner once we resolve attributes below
    {
        uint16_t l_cal_step[mss::PORTS_PER_MCS] = {0xFAC0, 0xFAC0};
        FAPI_TRY( FAPI_ATTR_SET(fapi2::ATTR_MSS_CAL_STEP_ENABLE, i_target, l_cal_step) );
    }

    // Check plug rules. We check the MCS, and this will iterate down to children as needed.
    FAPI_TRY( mss::plug_rule::enforce_plug_rules(i_target) );

fapi_try_exit:
    return fapi2::current_err;
}
<commit_msg>Disabling temp_refresh_mode<commit_after>/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p9/procedures/hwp/memory/p9_mss_eff_config.C $ */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2015,2019                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */

///
/// @file p9_mss_eff_config.C
/// @brief Command and Control for the memory subsystem - populate attributes
///
// *HWP HWP Owner: Andre Marin <aamarin@us.ibm.com>
// *HWP HWP Backup: Brian Silver <bsilver@us.ibm.com>
// *HWP Team: Memory
// *HWP Level: 2
// *HWP Consumed by: FSP:HB

#include <p9_mss_eff_config.H>

// std
#include <map>

// fapi2
#include <fapi2.H>

// mss lib
#include <lib/spd/common/spd_decoder.H>
#include <lib/spd/spd_factory.H>
#include <lib/utils/pos.H>
#include <lib/utils/checker.H>
#include <lib/utils/find.H>
#include <lib/shared/mss_kind.H>
#include <lib/utils/find.H>
#include <lib/dimm/eff_dimm.H>
#include <lib/eff_config/plug_rules.H>
///
/// @brief Configure the attributes for each controller
/// @param[in] i_target the controller (e.g., MCS)
/// @param[in] i_decode_spd_only options to set VPD and SPD attrs only
/// @return FAPI2_RC_SUCCESS iff ok
///
fapi2::ReturnCode p9_mss_eff_config( const fapi2::Target<fapi2::TARGET_TYPE_MCS>& i_target,
                                     const bool i_decode_spd_only )
{
    fapi2::ReturnCode l_rc;
    std::map<uint32_t, std::shared_ptr<mss::spd::decoder> > l_factory_caches;
    // Caches
    FAPI_TRY( mss::spd::populate_decoder_caches(i_target, l_factory_caches) );

    // We need to decode the VPD. We don't do this in the ctor as we need
    // the rank information and for that we need the SPD caches (which we get when we populate the cache.)
    // However, we need to do the VPD decode before the others so that they might
    // be able to use VPD information to make decisions about setting up eff attributes.
    if( !i_decode_spd_only )
    {
        // Always set VPD attributes unless we enable the SPD_ONLY flag
        // Enables skipping VPD decoder when a valid VPD template isn't available
        FAPI_TRY( mss::eff_dimm::decode_vpd(i_target),
                  "Unable to decode VPD for %s", mss::c_str(i_target) );
    }

    for( const auto& l_dimm : mss::find_targets<fapi2::TARGET_TYPE_DIMM>(i_target) )
    {
        std::shared_ptr<mss::eff_dimm> l_eff_dimm;

        const auto l_dimm_pos = mss::pos(l_dimm);

        // TODO RTC:152390 Create function to do map checking on cached values
        // Find decoder factory for this dimm position
        auto l_it = l_factory_caches.find(l_dimm_pos);

        FAPI_TRY( mss::check::spd::invalid_cache(l_dimm,
                  l_it != l_factory_caches.end(),
                  l_dimm_pos),
                  "Failed to get valid cache (main decoder)");

        FAPI_TRY( mss::eff_dimm::eff_dimm_factory( l_dimm, l_it->second, l_eff_dimm));

        FAPI_TRY( l_eff_dimm->dram_mfg_id() );
        FAPI_TRY( l_eff_dimm->dram_width() );
        FAPI_TRY( l_eff_dimm->dram_density() );
        FAPI_TRY( l_eff_dimm->ranks_per_dimm() );
        FAPI_TRY( l_eff_dimm->primary_stack_type() );
        FAPI_TRY( l_eff_dimm->dimm_size() );
        FAPI_TRY( l_eff_dimm->hybrid_memory_type() );
        FAPI_TRY( l_eff_dimm->dram_trefi() );
        FAPI_TRY( l_eff_dimm->dram_trfc() );
        FAPI_TRY( l_eff_dimm->dram_trfc_dlr() );
        FAPI_TRY( l_eff_dimm->rcd_mirror_mode() );
        FAPI_TRY( l_eff_dimm->dram_bank_bits() );
        FAPI_TRY( l_eff_dimm->dram_row_bits() );
        FAPI_TRY( l_eff_dimm->dram_dqs_time() );
        FAPI_TRY( l_eff_dimm->dram_tccd_l() );
        FAPI_TRY( l_eff_dimm->dimm_rc00() );
        FAPI_TRY( l_eff_dimm->dimm_rc01() );
        FAPI_TRY( l_eff_dimm->dimm_rc02() );
        FAPI_TRY( l_eff_dimm->dimm_rc03() );
        FAPI_TRY( l_eff_dimm->dimm_rc04() );
        FAPI_TRY( l_eff_dimm->dimm_rc05() );
        FAPI_TRY( l_eff_dimm->dimm_rc06_07() );
        FAPI_TRY( l_eff_dimm->dimm_rc08() );
        FAPI_TRY( l_eff_dimm->dimm_rc09() );
        FAPI_TRY( l_eff_dimm->dimm_rc10() );
        FAPI_TRY( l_eff_dimm->dimm_rc11() );
        FAPI_TRY( l_eff_dimm->dimm_rc12() );
        FAPI_TRY( l_eff_dimm->dimm_rc13() );
        FAPI_TRY( l_eff_dimm->dimm_rc14() );
        FAPI_TRY( l_eff_dimm->dimm_rc15() );
        FAPI_TRY( l_eff_dimm->dimm_rc1x() );
        FAPI_TRY( l_eff_dimm->dimm_rc2x() );
        FAPI_TRY( l_eff_dimm->dimm_rc3x() );
        FAPI_TRY( l_eff_dimm->dimm_rc4x() );
        FAPI_TRY( l_eff_dimm->dimm_rc5x() );
        FAPI_TRY( l_eff_dimm->dimm_rc6x() );
        FAPI_TRY( l_eff_dimm->dimm_rc7x() );
        FAPI_TRY( l_eff_dimm->dimm_rc8x() );
        FAPI_TRY( l_eff_dimm->dimm_rc9x() );
        FAPI_TRY( l_eff_dimm->dimm_rcax() );
        FAPI_TRY( l_eff_dimm->dimm_rcbx() );
        FAPI_TRY( l_eff_dimm->dram_twr() );
        FAPI_TRY( l_eff_dimm->read_burst_type() );
        FAPI_TRY( l_eff_dimm->dram_tm() );
        FAPI_TRY( l_eff_dimm->dram_cwl() );
        FAPI_TRY( l_eff_dimm->dram_lpasr() );
        FAPI_TRY( l_eff_dimm->dll_enable() );
        FAPI_TRY( l_eff_dimm->dll_reset() );
        FAPI_TRY( l_eff_dimm->write_level_enable() );
        FAPI_TRY( l_eff_dimm->output_buffer() );
        FAPI_TRY( l_eff_dimm->vref_dq_train_value() );
        FAPI_TRY( l_eff_dimm->vref_dq_train_range() );
        FAPI_TRY( l_eff_dimm->vref_dq_train_enable() );
        FAPI_TRY( l_eff_dimm->ca_parity_latency() );
        FAPI_TRY( l_eff_dimm->ca_parity_error_status() );
        FAPI_TRY( l_eff_dimm->ca_parity() );
        FAPI_TRY( l_eff_dimm->crc_error_clear() );
        FAPI_TRY( l_eff_dimm->odt_input_buffer() );
        FAPI_TRY( l_eff_dimm->post_package_repair() );
        FAPI_TRY( l_eff_dimm->read_preamble_train() );
        FAPI_TRY( l_eff_dimm->read_preamble() );
        FAPI_TRY( l_eff_dimm->write_preamble() );
        FAPI_TRY( l_eff_dimm->self_refresh_abort() );
        FAPI_TRY( l_eff_dimm->cs_to_cmd_addr_latency() );
        FAPI_TRY( l_eff_dimm->internal_vref_monitor() );
        FAPI_TRY( l_eff_dimm->max_powerdown_mode() );
        FAPI_TRY( l_eff_dimm->mpr_read_format() );
        FAPI_TRY( l_eff_dimm->temp_readout() );
        FAPI_TRY( l_eff_dimm->crc_wr_latency() );
        FAPI_TRY( l_eff_dimm->per_dram_addressability() );
        FAPI_TRY( l_eff_dimm->geardown_mode() );
        FAPI_TRY( l_eff_dimm->mpr_page() );
        FAPI_TRY( l_eff_dimm->mpr_mode() );
        FAPI_TRY( l_eff_dimm->write_crc() );
        FAPI_TRY( l_eff_dimm->zqcal_interval() );
        FAPI_TRY( l_eff_dimm->memcal_interval() );
        FAPI_TRY( l_eff_dimm->dram_trp() );
        FAPI_TRY( l_eff_dimm->dram_trcd() );
        FAPI_TRY( l_eff_dimm->dram_trc() );
        FAPI_TRY( l_eff_dimm->dram_twtr_l() );
        FAPI_TRY( l_eff_dimm->dram_twtr_s() );
        FAPI_TRY( l_eff_dimm->dram_trrd_s() );
        FAPI_TRY( l_eff_dimm->dram_trrd_l() );
        FAPI_TRY( l_eff_dimm->dram_trrd_dlr() );
        FAPI_TRY( l_eff_dimm->dram_tfaw() );
        FAPI_TRY( l_eff_dimm->dram_tfaw_dlr() );
        FAPI_TRY( l_eff_dimm->dram_tras() );
        FAPI_TRY( l_eff_dimm->dram_trtp() );
        FAPI_TRY( l_eff_dimm->read_dbi() );
        FAPI_TRY( l_eff_dimm->write_dbi() );
        FAPI_TRY( l_eff_dimm->additive_latency() );
        FAPI_TRY( l_eff_dimm->data_mask() );
        FAPI_TRY( l_eff_dimm->dimm_bc00());
        FAPI_TRY( l_eff_dimm->dimm_bc01());
        FAPI_TRY( l_eff_dimm->dimm_bc02());
        FAPI_TRY( l_eff_dimm->dimm_bc03());
        FAPI_TRY( l_eff_dimm->dimm_bc04());
        FAPI_TRY( l_eff_dimm->dimm_bc05());
        FAPI_TRY( l_eff_dimm->dimm_bc07());
        FAPI_TRY( l_eff_dimm->dimm_bc08());
        FAPI_TRY( l_eff_dimm->dimm_bc09());
        FAPI_TRY( l_eff_dimm->dimm_bc0a());
        FAPI_TRY( l_eff_dimm->dimm_bc0b());
        FAPI_TRY( l_eff_dimm->dimm_bc0c());
        FAPI_TRY( l_eff_dimm->dimm_bc0d());
        FAPI_TRY( l_eff_dimm->dimm_bc0e());
        FAPI_TRY( l_eff_dimm->dimm_bc0f());
        FAPI_TRY( l_eff_dimm->dram_rtt_nom () );
        FAPI_TRY( l_eff_dimm->dram_rtt_wr  () );
        FAPI_TRY( l_eff_dimm->dram_rtt_park() );

        //Let's do some checking
        FAPI_TRY( mss::check::temp_refresh_mode());
    }// dimm

    // TODO RTC:160060 Clean up hard coded values at bottom of eff_config
    // Don't set these attributes if we only want to set VPD attributes
    // This will be cleaner once we resolve attributes below
    {
        uint16_t l_cal_step[mss::PORTS_PER_MCS] = {0xFAC0, 0xFAC0};
        FAPI_TRY( FAPI_ATTR_SET(fapi2::ATTR_MSS_CAL_STEP_ENABLE, i_target, l_cal_step) );
    }

    // Check plug rules. We check the MCS, and this will iterate down to children as needed.
    FAPI_TRY( mss::plug_rule::enforce_plug_rules(i_target) );

fapi_try_exit:
    return fapi2::current_err;
}
<|endoftext|>


<commit_before>/*
 * Copyright 2014 Open Connectome Project (http://openconnecto.me)
 * Written by Da Zheng (zhengda1936@gmail.com)
 *
 * This file is part of FlashMatrix.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <unordered_map>

#include "io_interface.h"

#include "matrix_config.h"
#include "mem_worker_thread.h"
#include "EM_object.h"
#include "local_mem_buffer.h"

namespace fm
{

namespace detail
{

#ifdef USE_HWLOC
std::vector<int> get_cpus(int node_id)
{
	std::vector<int> io_cpus = safs::get_io_cpus();
	std::vector<int> logical_units = cpus.get_node(node_id).get_logical_units();
	std::set<int> cpu_set(logical_units.begin(), logical_units.end());
	// Remove the logical units where I/O threads run.
	for (size_t j = 0; j < io_cpus.size(); j++)
		cpu_set.erase(io_cpus[j]);
	return std::vector<int>(cpu_set.begin(), cpu_set.end());
}
#endif

mem_thread_pool::mem_thread_pool(int num_nodes, int nthreads_per_node)
{
	tot_num_tasks = 0;
	threads.resize(num_nodes);
	for (int i = 0; i < num_nodes; i++) {
		// Get the CPU cores that are in node i.
#ifdef USE_HWLOC
		std::vector<int> cpus = get_cpus(i);
#endif
		threads[i].resize(nthreads_per_node);
		for (int j = 0; j < nthreads_per_node; j++) {
			std::string name
				= std::string("mem-worker-") + itoa(i) + "-" + itoa(j);
#ifdef USE_HWLOC
			if (safs::get_io_cpus().empty())
				threads[i][j] = std::shared_ptr<pool_task_thread>(
						new pool_task_thread(i * nthreads_per_node + j, name, i));
			else
				threads[i][j] = std::shared_ptr<pool_task_thread>(
						new pool_task_thread(i * nthreads_per_node + j, name,
							cpus, i));
#else
			threads[i][j] = std::shared_ptr<pool_task_thread>(
					new pool_task_thread(i * nthreads_per_node + j, name, i));
#endif
			threads[i][j]->start();
		}
	}
	ntasks_per_node.resize(num_nodes);
}

/*
 * This method dispatches tasks in a round-robin fashion.
 */
void mem_thread_pool::process_task(int node_id, thread_task *task)
{
	if (node_id < 0)
		node_id = tot_num_tasks % get_num_nodes();

	assert((size_t) node_id < threads.size());
	size_t idx = ntasks_per_node[node_id] % threads[node_id].size();
	threads[node_id][idx]->add_task(task);
	ntasks_per_node[node_id]++;
	tot_num_tasks++;
}

void mem_thread_pool::wait4complete()
{
	for (size_t i = 0; i < threads.size(); i++) {
		size_t nthreads = threads[i].size();
		for (size_t j = 0; j < nthreads; j++)
			threads[i][j]->wait4complete();
	}

	// After all workers complete, we should try to clear the memory buffers
	// in each worker thread to reduce memory consumption.
	// We might want to keep the memory buffer for I/O on dense matrices.
	if (matrix_conf.is_keep_mem_buf())
		detail::local_mem_buffer::clear_bufs(
				detail::local_mem_buffer::MAT_PORTION);
	else
		detail::local_mem_buffer::clear_bufs();
}

size_t mem_thread_pool::get_num_pending() const
{
	size_t ret = 0;
	for (size_t i = 0; i < threads.size(); i++) {
		size_t nthreads = threads[i].size();
		for (size_t j = 0; j < nthreads; j++)
			ret += threads[i][j]->get_num_pending();
	}
	return ret;
}

static mem_thread_pool::ptr global_threads;
enum thread_pool_state {
	UNINIT,
	ACTIVE,
	INACTIVE,
};
static thread_pool_state pool_state = thread_pool_state::UNINIT;

/*
 * When we disable thread pool, we use the main thread to perform
 * computation.
 */
bool mem_thread_pool::disable_thread_pool()
{
	pool_state = thread_pool_state::INACTIVE;
	return true;
}

bool mem_thread_pool::enable_thread_pool()
{
	pool_state = thread_pool_state::ACTIVE;
	return true;
}

mem_thread_pool::ptr mem_thread_pool::get_global_mem_threads()
{
	assert(pool_state != thread_pool_state::INACTIVE);
	if (global_threads == NULL) {
		int nthreads_per_node
			= matrix_conf.get_num_DM_threads() / matrix_conf.get_num_nodes();
		assert(nthreads_per_node > 0);
		global_threads = mem_thread_pool::create(matrix_conf.get_num_nodes(),
				nthreads_per_node);
		enable_thread_pool();
	}
	return global_threads;
}

size_t mem_thread_pool::get_global_num_threads()
{
	// When we disable the thread pool, we use the main thread for computation.
	// So the number of threads is 1.
	if (pool_state == thread_pool_state::INACTIVE)
		return 1;
	else
		return get_global_mem_threads()->get_num_threads();
}

int mem_thread_pool::get_curr_thread_id()
{
	// When we disable the thread pool, we use the main thread for computation.
	// And we use 0 as the thread id of the main thread.
	if (pool_state == thread_pool_state::INACTIVE)
		return 0;
	else {
		detail::pool_task_thread *curr
			= dynamic_cast<detail::pool_task_thread *>(thread::get_curr_thread());
		if (curr)
			return curr->get_pool_thread_id();
		else
			return -1;
	}
}

void mem_thread_pool::init_global_mem_threads(int num_nodes,
		int nthreads_per_node)
{
	if (global_threads == NULL) {
		global_threads = mem_thread_pool::create(num_nodes, nthreads_per_node);
		enable_thread_pool();
	}
}

void mem_thread_pool::destroy()
{
	global_threads = NULL;
}

void io_worker_task::run()
{
	std::vector<safs::io_interface::ptr> ios;
	pthread_spin_lock(&lock);
	for (auto it = EM_objs.begin(); it != EM_objs.end(); it++) {
		std::vector<safs::io_interface::ptr> tmp = (*it)->create_ios();
		ios.insert(ios.end(), tmp.begin(), tmp.end());
	}
	pthread_spin_unlock(&lock);
	safs::io_select::ptr select = safs::create_io_select(ios);

	// The task runs until there are no tasks left in the queue.
	while (dispatch->issue_task())
		safs::wait4ios(select, max_pending_ios);
	// Test if all I/O instances have processed all requests.
	size_t num_pending = safs::wait4ios(select, 0);
	assert(num_pending == 0);

	pthread_spin_lock(&lock);
	EM_objs.clear();
	pthread_spin_unlock(&lock);

	for (size_t i = 0; i < ios.size(); i++) {
		portion_callback &cb = static_cast<portion_callback &>(
				ios[i]->get_callback());
		assert(!cb.has_callback());
	}
}

global_counter::global_counter()
{
	counts.resize(mem_thread_pool::get_global_num_threads());
	reset();
}

void global_counter::inc(size_t val)
{
	int id = mem_thread_pool::get_curr_thread_id();
	counts[id].count += val;
}

void global_counter::reset()
{
	for (size_t i = 0; i < counts.size(); i++)
		counts[i].count = 0;
}

size_t global_counter::get() const
{
	size_t tot = 0;
	for (size_t i = 0; i < counts.size(); i++)
		tot += counts[i].count;
	return tot;
}

}

}
<commit_msg>[Matrix]: fix a bug in global_counter.<commit_after>/*
 * Copyright 2014 Open Connectome Project (http://openconnecto.me)
 * Written by Da Zheng (zhengda1936@gmail.com)
 *
 * This file is part of FlashMatrix.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <unordered_map>

#include "io_interface.h"

#include "matrix_config.h"
#include "mem_worker_thread.h"
#include "EM_object.h"
#include "local_mem_buffer.h"

namespace fm
{

namespace detail
{

#ifdef USE_HWLOC
std::vector<int> get_cpus(int node_id)
{
	std::vector<int> io_cpus = safs::get_io_cpus();
	std::vector<int> logical_units = cpus.get_node(node_id).get_logical_units();
	std::set<int> cpu_set(logical_units.begin(), logical_units.end());
	// Remove the logical units where I/O threads run.
	for (size_t j = 0; j < io_cpus.size(); j++)
		cpu_set.erase(io_cpus[j]);
	return std::vector<int>(cpu_set.begin(), cpu_set.end());
}
#endif

mem_thread_pool::mem_thread_pool(int num_nodes, int nthreads_per_node)
{
	tot_num_tasks = 0;
	threads.resize(num_nodes);
	for (int i = 0; i < num_nodes; i++) {
		// Get the CPU cores that are in node i.
#ifdef USE_HWLOC
		std::vector<int> cpus = get_cpus(i);
#endif
		threads[i].resize(nthreads_per_node);
		for (int j = 0; j < nthreads_per_node; j++) {
			std::string name
				= std::string("mem-worker-") + itoa(i) + "-" + itoa(j);
#ifdef USE_HWLOC
			if (safs::get_io_cpus().empty())
				threads[i][j] = std::shared_ptr<pool_task_thread>(
						new pool_task_thread(i * nthreads_per_node + j, name, i));
			else
				threads[i][j] = std::shared_ptr<pool_task_thread>(
						new pool_task_thread(i * nthreads_per_node + j, name,
							cpus, i));
#else
			threads[i][j] = std::shared_ptr<pool_task_thread>(
					new pool_task_thread(i * nthreads_per_node + j, name, i));
#endif
			threads[i][j]->start();
		}
	}
	ntasks_per_node.resize(num_nodes);
}

/*
 * This method dispatches tasks in a round-robin fashion.
 */
void mem_thread_pool::process_task(int node_id, thread_task *task)
{
	if (node_id < 0)
		node_id = tot_num_tasks % get_num_nodes();

	assert((size_t) node_id < threads.size());
	size_t idx = ntasks_per_node[node_id] % threads[node_id].size();
	threads[node_id][idx]->add_task(task);
	ntasks_per_node[node_id]++;
	tot_num_tasks++;
}

void mem_thread_pool::wait4complete()
{
	for (size_t i = 0; i < threads.size(); i++) {
		size_t nthreads = threads[i].size();
		for (size_t j = 0; j < nthreads; j++)
			threads[i][j]->wait4complete();
	}

	// After all workers complete, we should try to clear the memory buffers
	// in each worker thread to reduce memory consumption.
	// We might want to keep the memory buffer for I/O on dense matrices.
	if (matrix_conf.is_keep_mem_buf())
		detail::local_mem_buffer::clear_bufs(
				detail::local_mem_buffer::MAT_PORTION);
	else
		detail::local_mem_buffer::clear_bufs();
}

size_t mem_thread_pool::get_num_pending() const
{
	size_t ret = 0;
	for (size_t i = 0; i < threads.size(); i++) {
		size_t nthreads = threads[i].size();
		for (size_t j = 0; j < nthreads; j++)
			ret += threads[i][j]->get_num_pending();
	}
	return ret;
}

static mem_thread_pool::ptr global_threads;
enum thread_pool_state {
	UNINIT,
	ACTIVE,
	INACTIVE,
};
static thread_pool_state pool_state = thread_pool_state::UNINIT;

/*
 * When we disable thread pool, we use the main thread to perform
 * computation.
 */
bool mem_thread_pool::disable_thread_pool()
{
	pool_state = thread_pool_state::INACTIVE;
	return true;
}

bool mem_thread_pool::enable_thread_pool()
{
	pool_state = thread_pool_state::ACTIVE;
	return true;
}

mem_thread_pool::ptr mem_thread_pool::get_global_mem_threads()
{
	assert(pool_state != thread_pool_state::INACTIVE);
	if (global_threads == NULL) {
		int nthreads_per_node
			= matrix_conf.get_num_DM_threads() / matrix_conf.get_num_nodes();
		assert(nthreads_per_node > 0);
		global_threads = mem_thread_pool::create(matrix_conf.get_num_nodes(),
				nthreads_per_node);
		enable_thread_pool();
	}
	return global_threads;
}

size_t mem_thread_pool::get_global_num_threads()
{
	// When we disable the thread pool, we use the main thread for computation.
	// So the number of threads is 1.
	if (pool_state == thread_pool_state::INACTIVE)
		return 1;
	else
		return get_global_mem_threads()->get_num_threads();
}

int mem_thread_pool::get_curr_thread_id()
{
	// When we disable the thread pool, we use the main thread for computation.
	// And we use 0 as the thread id of the main thread.
	if (pool_state == thread_pool_state::INACTIVE)
		return 0;
	else {
		detail::pool_task_thread *curr
			= dynamic_cast<detail::pool_task_thread *>(thread::get_curr_thread());
		if (curr)
			return curr->get_pool_thread_id();
		else
			return -1;
	}
}

void mem_thread_pool::init_global_mem_threads(int num_nodes,
		int nthreads_per_node)
{
	if (global_threads == NULL) {
		global_threads = mem_thread_pool::create(num_nodes, nthreads_per_node);
		enable_thread_pool();
	}
}

void mem_thread_pool::destroy()
{
	global_threads = NULL;
}

void io_worker_task::run()
{
	std::vector<safs::io_interface::ptr> ios;
	pthread_spin_lock(&lock);
	for (auto it = EM_objs.begin(); it != EM_objs.end(); it++) {
		std::vector<safs::io_interface::ptr> tmp = (*it)->create_ios();
		ios.insert(ios.end(), tmp.begin(), tmp.end());
	}
	pthread_spin_unlock(&lock);
	safs::io_select::ptr select = safs::create_io_select(ios);

	// The task runs until there are no tasks left in the queue.
	while (dispatch->issue_task())
		safs::wait4ios(select, max_pending_ios);
	// Test if all I/O instances have processed all requests.
	size_t num_pending = safs::wait4ios(select, 0);
	assert(num_pending == 0);

	pthread_spin_lock(&lock);
	EM_objs.clear();
	pthread_spin_unlock(&lock);

	for (size_t i = 0; i < ios.size(); i++) {
		portion_callback &cb = static_cast<portion_callback &>(
				ios[i]->get_callback());
		assert(!cb.has_callback());
	}
}

global_counter::global_counter()
{
	counts.resize(mem_thread_pool::get_global_num_threads() + 1);
	reset();
}

void global_counter::inc(size_t val)
{
	int id = mem_thread_pool::get_curr_thread_id();
	// the main thread has id of -1.
	counts[id + 1].count += val;
}

void global_counter::reset()
{
	for (size_t i = 0; i < counts.size(); i++)
		counts[i].count = 0;
}

size_t global_counter::get() const
{
	size_t tot = 0;
	for (size_t i = 0; i < counts.size(); i++)
		tot += counts[i].count;
	return tot;
}

}

}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: fmobjfac.cxx,v $
 *
 *  $Revision: 1.9 $
 *
 *  last change: $Author: kz $ $Date: 2003-12-11 12:17:05 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  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
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/
#pragma hdrstop

#ifndef _COMPHELPER_STLTYPES_HXX_
#include <comphelper/stl_types.hxx>
#endif

#ifndef _SVDOBJ_HXX
#include "svdobj.hxx"
#endif

#ifndef _SVX_FMTOOLS_HXX
#include "fmtools.hxx"
#endif

#ifndef _SVX_FMSERVS_HXX
#include "fmservs.hxx"
#endif

#ifndef _FM_FMOBJFAC_HXX
#include "fmobjfac.hxx"
#endif

#ifndef _FM_FMGLOB_HXX
#include "fmglob.hxx"
#endif

#ifndef _FM_FMOBJ_HXX
#include "fmobj.hxx"
#endif

#ifndef _SVX_FMSHIMP_HXX
#include "fmshimp.hxx"
#endif

#ifndef _FM_FMSHELL_HXX
#include "fmshell.hxx"
#endif

#ifndef _SVX_SVXIDS_HRC
#include "svxids.hrc"
#endif

#ifndef _SVX_TBXFORM_HXX
#include "tbxform.hxx"
#endif

#ifndef _TOOLS_RESID_HXX //autogen
#include <tools/resid.hxx>
#endif

#ifndef _SVX_FMRESIDS_HRC
#include "fmresids.hrc"
#endif

#ifndef _SHL_HXX
#include <tools/shl.hxx>
#endif

#ifndef _SVX_DIALMGR_HXX
#include "dialmgr.hxx"
#endif

#ifndef _SVX_FMSERVS_HXX
#include "fmservs.hxx"
#endif

#ifndef _SVX_TABWIN_HXX
#include "tabwin.hxx"
#endif

#ifndef _SVX_FMEXPL_HXX
#include "fmexpl.hxx"
#endif

#ifndef _SVX_FILTNAV_HXX
#include "filtnav.hxx"
#endif

#ifndef _SVX_FMPROP_HRC
#include "fmprop.hrc"
#endif
#ifndef SVX_FMPROPBRW_HXX
#include "fmPropBrw.hxx"
#endif

using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::beans;
using namespace ::svxform;

/*************************************************************************
|*
|* Ctor
|*
\************************************************************************/
FmFormObjFactory::FmFormObjFactory()
{
    SdrObjFactory::InsertMakeObjectHdl(LINK(this, FmFormObjFactory, MakeObject));

    //////////////////////////////////////////////////////////////////////
    // Konfigurations-::com::sun::star::frame::Controller und NavigationBar registrieren
    SvxFmTbxCtlConfig::RegisterControl( SID_FM_CONFIG );
    SvxFmTbxCtlAbsRec::RegisterControl( SID_FM_RECORD_ABSOLUTE );
    SvxFmTbxCtlRecText::RegisterControl( SID_FM_RECORD_TEXT );
    SvxFmTbxCtlRecFromText::RegisterControl( SID_FM_RECORD_FROM_TEXT );
    SvxFmTbxCtlRecTotal::RegisterControl( SID_FM_RECORD_TOTAL );
    SvxFmTbxPrevRec::RegisterControl( SID_FM_RECORD_PREV );
    SvxFmTbxNextRec::RegisterControl( SID_FM_RECORD_NEXT );
    ControlConversionMenuController::RegisterControl(SID_FM_CHANGECONTROLTYPE);

    // Registrieung von globalen fenstern
    FmFieldWinMgr::RegisterChildWindow();
    FmPropBrwMgr::RegisterChildWindow();
    NavigatorFrameManager::RegisterChildWindow();
    FmFilterNavigatorWinMgr::RegisterChildWindow();

    //////////////////////////////////////////////////////////////////////
    // Interface fuer die Formshell registrieren
    FmFormShell::RegisterInterface(0);

    ImplSmartRegisterUnoServices();

}

/*************************************************************************
|*
|* Dtor
|*
\************************************************************************/
FmFormObjFactory::~FmFormObjFactory()
{
}

/*************************************************************************
|*
|* ::com::sun::star::form::Form-Objekte erzeugen
|*
\************************************************************************/
namespace
{
    void    lcl_initProperty( FmFormObj* _pObject, const ::rtl::OUString& _rPropName, const Any& _rValue )
    {
        try
        {
            Reference< XPropertySet >  xModelSet( _pObject->GetUnoControlModel(), UNO_QUERY );
            if ( xModelSet.is() )
                xModelSet->setPropertyValue( _rPropName, _rValue );
        }
        catch( const Exception& )
        {
            DBG_ERROR( "lcl_initProperty: caught an exception!" );
        }
    }
}

IMPL_LINK(FmFormObjFactory, MakeObject, SdrObjFactory*, pObjFactory)
{
    if (pObjFactory->nInventor == FmFormInventor)
    {
        switch (pObjFactory->nIdentifier)
        {
            case OBJ_FM_CONTROL:    // allgemeines Object
            {
                pObjFactory->pNewObj = new FmFormObj(pObjFactory->nIdentifier);
            }   break;
            case OBJ_FM_EDIT:
            {
                pObjFactory->pNewObj = new FmFormObj(FM_COMPONENT_EDIT,pObjFactory->nIdentifier);
            }   break;
            case OBJ_FM_BUTTON:
            {
                pObjFactory->pNewObj = new FmFormObj(FM_COMPONENT_COMMANDBUTTON,pObjFactory->nIdentifier);
            }   break;
            case OBJ_FM_FIXEDTEXT:
            {
                pObjFactory->pNewObj = new FmFormObj(FM_COMPONENT_FIXEDTEXT,pObjFactory->nIdentifier);
            }   break;
            case OBJ_FM_LISTBOX:
            {
                pObjFactory->pNewObj = new FmFormObj(FM_COMPONENT_LISTBOX,pObjFactory->nIdentifier);
            }   break;
            case OBJ_FM_CHECKBOX:
            {
                pObjFactory->pNewObj = new FmFormObj(FM_COMPONENT_CHECKBOX,pObjFactory->nIdentifier);
            }   break;
            case OBJ_FM_RADIOBUTTON:
            {
                pObjFactory->pNewObj = new FmFormObj(FM_COMPONENT_RADIOBUTTON,pObjFactory->nIdentifier);
            }   break;
            case OBJ_FM_GROUPBOX:
            {
                pObjFactory->pNewObj = new FmFormObj(FM_COMPONENT_GROUPBOX,pObjFactory->nIdentifier);
            }   break;
            case OBJ_FM_COMBOBOX:
            {
                pObjFactory->pNewObj = new FmFormObj(FM_COMPONENT_COMBOBOX,pObjFactory->nIdentifier);
                lcl_initProperty( static_cast< FmFormObj* >( pObjFactory->pNewObj ), FM_PROP_DROPDOWN, makeAny( sal_True ) );

            }   break;
            case OBJ_FM_GRID:
            {
                pObjFactory->pNewObj = new FmFormObj(FM_COMPONENT_GRID,pObjFactory->nIdentifier);
            }   break;
            case OBJ_FM_IMAGEBUTTON:
            {
                pObjFactory->pNewObj = new FmFormObj(FM_COMPONENT_IMAGEBUTTON,pObjFactory->nIdentifier);
            }   break;
            case OBJ_FM_FILECONTROL:
            {
                pObjFactory->pNewObj = new FmFormObj(FM_COMPONENT_FILECONTROL,pObjFactory->nIdentifier);
            }   break;
            case OBJ_FM_DATEFIELD:
            {
                pObjFactory->pNewObj = new FmFormObj(FM_COMPONENT_DATEFIELD,pObjFactory->nIdentifier);
            }   break;
            case OBJ_FM_TIMEFIELD:
            {
                pObjFactory->pNewObj = new FmFormObj(FM_COMPONENT_TIMEFIELD,pObjFactory->nIdentifier);
                lcl_initProperty( static_cast< FmFormObj* >( pObjFactory->pNewObj ), FM_PROP_TIMEMAX, makeAny( (sal_Int32)( Time( 23, 59, 59, 99 ).GetTime() ) ) );
            }   break;
            case OBJ_FM_NUMERICFIELD:
            {
                pObjFactory->pNewObj = new FmFormObj(FM_COMPONENT_NUMERICFIELD,pObjFactory->nIdentifier);
            }   break;
            case OBJ_FM_CURRENCYFIELD:
            {
                pObjFactory->pNewObj = new FmFormObj(FM_COMPONENT_CURRENCYFIELD,pObjFactory->nIdentifier);
            }   break;
            case OBJ_FM_PATTERNFIELD:
            {
                pObjFactory->pNewObj = new FmFormObj(FM_COMPONENT_PATTERNFIELD,pObjFactory->nIdentifier);
            }   break;
            case OBJ_FM_HIDDEN:
            {
                pObjFactory->pNewObj = new FmFormObj(FM_COMPONENT_HIDDEN,pObjFactory->nIdentifier);
            }   break;
            case OBJ_FM_IMAGECONTROL:
            {
                pObjFactory->pNewObj = new FmFormObj(FM_COMPONENT_IMAGECONTROL,pObjFactory->nIdentifier);
            }   break;
            case OBJ_FM_FORMATTEDFIELD:
            {
                pObjFactory->pNewObj = new FmFormObj(FM_COMPONENT_FORMATTEDFIELD,pObjFactory->nIdentifier);
            }   break;
            case OBJ_FM_SCROLLBAR:
            {
                pObjFactory->pNewObj = new FmFormObj( FM_SUN_COMPONENT_SCROLLBAR, pObjFactory->nIdentifier );
                lcl_initProperty( static_cast< FmFormObj* >( pObjFactory->pNewObj ), FM_PROP_BORDER, makeAny( (sal_Int16)0 ) );
            }   break;
            case OBJ_FM_SPINBUTTON:
            {
                pObjFactory->pNewObj = new FmFormObj( FM_SUN_COMPONENT_SPINBUTTON, pObjFactory->nIdentifier );
                lcl_initProperty( static_cast< FmFormObj* >( pObjFactory->pNewObj ), FM_PROP_BORDER, makeAny( (sal_Int16)0 ) );
            }   break;
            default:
                return 0;
        }
    }

    return 0;
}

<commit_msg>INTEGRATION: CWS dialogdiet (1.8.480); FILE MERGED 2004/01/19 20:50:34 mba 1.8.480.2: RESYNC: (1.8-1.9); FILE MERGED 2003/11/28 17:49:12 mba 1.8.480.1: #i22972#: make factory aware of multiple inits<commit_after>/*************************************************************************
 *
 *  $RCSfile: fmobjfac.cxx,v $
 *
 *  $Revision: 1.10 $
 *
 *  last change: $Author: hr $ $Date: 2004-02-03 19:07:29 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  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
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/
#pragma hdrstop

#ifndef _COMPHELPER_STLTYPES_HXX_
#include <comphelper/stl_types.hxx>
#endif

#ifndef _SVDOBJ_HXX
#include "svdobj.hxx"
#endif

#ifndef _SVX_FMTOOLS_HXX
#include "fmtools.hxx"
#endif

#ifndef _SVX_FMSERVS_HXX
#include "fmservs.hxx"
#endif

#ifndef _FM_FMOBJFAC_HXX
#include "fmobjfac.hxx"
#endif

#ifndef _FM_FMGLOB_HXX
#include "fmglob.hxx"
#endif

#ifndef _FM_FMOBJ_HXX
#include "fmobj.hxx"
#endif

#ifndef _SVX_FMSHIMP_HXX
#include "fmshimp.hxx"
#endif

#ifndef _FM_FMSHELL_HXX
#include "fmshell.hxx"
#endif

#ifndef _SVX_SVXIDS_HRC
#include "svxids.hrc"
#endif

#ifndef _SVX_TBXFORM_HXX
#include "tbxform.hxx"
#endif

#ifndef _TOOLS_RESID_HXX //autogen
#include <tools/resid.hxx>
#endif

#ifndef _SVX_FMRESIDS_HRC
#include "fmresids.hrc"
#endif

#ifndef _SHL_HXX
#include <tools/shl.hxx>
#endif

#ifndef _SVX_DIALMGR_HXX
#include "dialmgr.hxx"
#endif

#ifndef _SVX_FMSERVS_HXX
#include "fmservs.hxx"
#endif

#ifndef _SVX_TABWIN_HXX
#include "tabwin.hxx"
#endif

#ifndef _SVX_FMEXPL_HXX
#include "fmexpl.hxx"
#endif

#ifndef _SVX_FILTNAV_HXX
#include "filtnav.hxx"
#endif

#ifndef _SVX_FMPROP_HRC
#include "fmprop.hrc"
#endif
#ifndef SVX_FMPROPBRW_HXX
#include "fmPropBrw.hxx"
#endif

using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::beans;
using namespace ::svxform;

static BOOL bInit = FALSE;

/*************************************************************************
|*
|* Ctor
|*
\************************************************************************/
FmFormObjFactory::FmFormObjFactory()
{
    if ( !bInit )
    {
        SdrObjFactory::InsertMakeObjectHdl(LINK(this, FmFormObjFactory, MakeObject));

        //////////////////////////////////////////////////////////////////////
        // Konfigurations-::com::sun::star::frame::Controller und NavigationBar registrieren
        SvxFmTbxCtlConfig::RegisterControl( SID_FM_CONFIG );
        SvxFmTbxCtlAbsRec::RegisterControl( SID_FM_RECORD_ABSOLUTE );
        SvxFmTbxCtlRecText::RegisterControl( SID_FM_RECORD_TEXT );
        SvxFmTbxCtlRecFromText::RegisterControl( SID_FM_RECORD_FROM_TEXT );
        SvxFmTbxCtlRecTotal::RegisterControl( SID_FM_RECORD_TOTAL );
        SvxFmTbxPrevRec::RegisterControl( SID_FM_RECORD_PREV );
        SvxFmTbxNextRec::RegisterControl( SID_FM_RECORD_NEXT );
        ControlConversionMenuController::RegisterControl(SID_FM_CHANGECONTROLTYPE);

        // Registrieung von globalen fenstern
        FmFieldWinMgr::RegisterChildWindow();
        FmPropBrwMgr::RegisterChildWindow();
        NavigatorFrameManager::RegisterChildWindow();
        FmFilterNavigatorWinMgr::RegisterChildWindow();

        //////////////////////////////////////////////////////////////////////
        // Interface fuer die Formshell registrieren
        FmFormShell::RegisterInterface(0);

        ImplSmartRegisterUnoServices();
        bInit = TRUE;
    }
}

/*************************************************************************
|*
|* Dtor
|*
\************************************************************************/
FmFormObjFactory::~FmFormObjFactory()
{
}

/*************************************************************************
|*
|* ::com::sun::star::form::Form-Objekte erzeugen
|*
\************************************************************************/
namespace
{
    void    lcl_initProperty( FmFormObj* _pObject, const ::rtl::OUString& _rPropName, const Any& _rValue )
    {
        try
        {
            Reference< XPropertySet >  xModelSet( _pObject->GetUnoControlModel(), UNO_QUERY );
            if ( xModelSet.is() )
                xModelSet->setPropertyValue( _rPropName, _rValue );
        }
        catch( const Exception& )
        {
            DBG_ERROR( "lcl_initProperty: caught an exception!" );
        }
    }
}

IMPL_LINK(FmFormObjFactory, MakeObject, SdrObjFactory*, pObjFactory)
{
    if (pObjFactory->nInventor == FmFormInventor)
    {
        switch (pObjFactory->nIdentifier)
        {
            case OBJ_FM_CONTROL:    // allgemeines Object
            {
                pObjFactory->pNewObj = new FmFormObj(pObjFactory->nIdentifier);
            }   break;
            case OBJ_FM_EDIT:
            {
                pObjFactory->pNewObj = new FmFormObj(FM_COMPONENT_EDIT,pObjFactory->nIdentifier);
            }   break;
            case OBJ_FM_BUTTON:
            {
                pObjFactory->pNewObj = new FmFormObj(FM_COMPONENT_COMMANDBUTTON,pObjFactory->nIdentifier);
            }   break;
            case OBJ_FM_FIXEDTEXT:
            {
                pObjFactory->pNewObj = new FmFormObj(FM_COMPONENT_FIXEDTEXT,pObjFactory->nIdentifier);
            }   break;
            case OBJ_FM_LISTBOX:
            {
                pObjFactory->pNewObj = new FmFormObj(FM_COMPONENT_LISTBOX,pObjFactory->nIdentifier);
            }   break;
            case OBJ_FM_CHECKBOX:
            {
                pObjFactory->pNewObj = new FmFormObj(FM_COMPONENT_CHECKBOX,pObjFactory->nIdentifier);
            }   break;
            case OBJ_FM_RADIOBUTTON:
            {
                pObjFactory->pNewObj = new FmFormObj(FM_COMPONENT_RADIOBUTTON,pObjFactory->nIdentifier);
            }   break;
            case OBJ_FM_GROUPBOX:
            {
                pObjFactory->pNewObj = new FmFormObj(FM_COMPONENT_GROUPBOX,pObjFactory->nIdentifier);
            }   break;
            case OBJ_FM_COMBOBOX:
            {
                pObjFactory->pNewObj = new FmFormObj(FM_COMPONENT_COMBOBOX,pObjFactory->nIdentifier);
                lcl_initProperty( static_cast< FmFormObj* >( pObjFactory->pNewObj ), FM_PROP_DROPDOWN, makeAny( sal_True ) );

            }   break;
            case OBJ_FM_GRID:
            {
                pObjFactory->pNewObj = new FmFormObj(FM_COMPONENT_GRID,pObjFactory->nIdentifier);
            }   break;
            case OBJ_FM_IMAGEBUTTON:
            {
                pObjFactory->pNewObj = new FmFormObj(FM_COMPONENT_IMAGEBUTTON,pObjFactory->nIdentifier);
            }   break;
            case OBJ_FM_FILECONTROL:
            {
                pObjFactory->pNewObj = new FmFormObj(FM_COMPONENT_FILECONTROL,pObjFactory->nIdentifier);
            }   break;
            case OBJ_FM_DATEFIELD:
            {
                pObjFactory->pNewObj = new FmFormObj(FM_COMPONENT_DATEFIELD,pObjFactory->nIdentifier);
            }   break;
            case OBJ_FM_TIMEFIELD:
            {
                pObjFactory->pNewObj = new FmFormObj(FM_COMPONENT_TIMEFIELD,pObjFactory->nIdentifier);
                lcl_initProperty( static_cast< FmFormObj* >( pObjFactory->pNewObj ), FM_PROP_TIMEMAX, makeAny( (sal_Int32)( Time( 23, 59, 59, 99 ).GetTime() ) ) );
            }   break;
            case OBJ_FM_NUMERICFIELD:
            {
                pObjFactory->pNewObj = new FmFormObj(FM_COMPONENT_NUMERICFIELD,pObjFactory->nIdentifier);
            }   break;
            case OBJ_FM_CURRENCYFIELD:
            {
                pObjFactory->pNewObj = new FmFormObj(FM_COMPONENT_CURRENCYFIELD,pObjFactory->nIdentifier);
            }   break;
            case OBJ_FM_PATTERNFIELD:
            {
                pObjFactory->pNewObj = new FmFormObj(FM_COMPONENT_PATTERNFIELD,pObjFactory->nIdentifier);
            }   break;
            case OBJ_FM_HIDDEN:
            {
                pObjFactory->pNewObj = new FmFormObj(FM_COMPONENT_HIDDEN,pObjFactory->nIdentifier);
            }   break;
            case OBJ_FM_IMAGECONTROL:
            {
                pObjFactory->pNewObj = new FmFormObj(FM_COMPONENT_IMAGECONTROL,pObjFactory->nIdentifier);
            }   break;
            case OBJ_FM_FORMATTEDFIELD:
            {
                pObjFactory->pNewObj = new FmFormObj(FM_COMPONENT_FORMATTEDFIELD,pObjFactory->nIdentifier);
            }   break;
            case OBJ_FM_SCROLLBAR:
            {
                pObjFactory->pNewObj = new FmFormObj( FM_SUN_COMPONENT_SCROLLBAR, pObjFactory->nIdentifier );
                lcl_initProperty( static_cast< FmFormObj* >( pObjFactory->pNewObj ), FM_PROP_BORDER, makeAny( (sal_Int16)0 ) );
            }   break;
            case OBJ_FM_SPINBUTTON:
            {
                pObjFactory->pNewObj = new FmFormObj( FM_SUN_COMPONENT_SPINBUTTON, pObjFactory->nIdentifier );
                lcl_initProperty( static_cast< FmFormObj* >( pObjFactory->pNewObj ), FM_PROP_BORDER, makeAny( (sal_Int16)0 ) );
            }   break;
            default:
                return 0;
        }
    }

    return 0;
}

<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: annotsh.hxx,v $
 *
 *  $Revision: 1.2 $
 *
 *  last change: $Author: rt $ $Date: 2008-02-19 13:55:58 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    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
 *
 ************************************************************************/
#ifndef _SWANNOTSH_HXX
#define _SWANNOTSH_HXX

#include <sfx2/shell.hxx>
#include "shellid.hxx"
#include "swmodule.hxx"

class SwView;
class SwAnnotationShell: public SfxShell
{
    SwView&     rView;

public:
    SFX_DECL_INTERFACE(SW_ANNOTATIONSHELL)
    TYPEINFO();

                SwAnnotationShell(SwView&);
    virtual     ~SwAnnotationShell();

    void        StateDisableItems(SfxItemSet &);
    void        Exec(SfxRequest &);

    void        GetState(SfxItemSet &);
    void        StateInsert(SfxItemSet &rSet);

    void        NoteExec(SfxRequest &);
    void        GetNoteState(SfxItemSet &);

    void        ExecLingu(SfxRequest &rReq);
    void        GetLinguState(SfxItemSet &);

    void        ExecClpbrd(SfxRequest &rReq);
    void        StateClpbrd(SfxItemSet &rSet);

    void        ExecTransliteration(SfxRequest &);

    void        ExecUndo(SfxRequest &rReq);
    void        StateUndo(SfxItemSet &rSet);

    void        InsertSymbol(SfxRequest& rReq);

    virtual SfxUndoManager*     GetUndoManager();
};

#endif
<commit_msg>INTEGRATION: CWS changefileheader (1.2.78); FILE MERGED 2008/03/31 16:58:26 rt 1.2.78.1: #i87441# Change license header to LPGL v3.<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: annotsh.hxx,v $
 * $Revision: 1.3 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org 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 version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/
#ifndef _SWANNOTSH_HXX
#define _SWANNOTSH_HXX

#include <sfx2/shell.hxx>
#include "shellid.hxx"
#include "swmodule.hxx"

class SwView;
class SwAnnotationShell: public SfxShell
{
    SwView&     rView;

public:
    SFX_DECL_INTERFACE(SW_ANNOTATIONSHELL)
    TYPEINFO();

                SwAnnotationShell(SwView&);
    virtual     ~SwAnnotationShell();

    void        StateDisableItems(SfxItemSet &);
    void        Exec(SfxRequest &);

    void        GetState(SfxItemSet &);
    void        StateInsert(SfxItemSet &rSet);

    void        NoteExec(SfxRequest &);
    void        GetNoteState(SfxItemSet &);

    void        ExecLingu(SfxRequest &rReq);
    void        GetLinguState(SfxItemSet &);

    void        ExecClpbrd(SfxRequest &rReq);
    void        StateClpbrd(SfxItemSet &rSet);

    void        ExecTransliteration(SfxRequest &);

    void        ExecUndo(SfxRequest &rReq);
    void        StateUndo(SfxItemSet &rSet);

    void        InsertSymbol(SfxRequest& rReq);

    virtual SfxUndoManager*     GetUndoManager();
};

#endif
<|endoftext|>